Fredrick Lackey - 316 - Feb 15, 2014

Any way to force the SqlServer provider in OrmLite to init a column using char instead of varchar?  Maybe something like a FixedLength attribute?

You can use the [StringLength] Attribute, a list of all of ServiceStack’s supported DataAnnotation attributes can be found on: https://github.com/ServiceStack/ServiceStack/tree/master/src/ServiceStack.Interfaces/DataAnnotations

Fredrick Lackey:

Yeah, I found this earlier and attempted to set both the min and max lengths.  No luck.  Regardless of the combination, any string field is always created as a varchar when the table is created.

ok yeah, I meant that’s how you define variable sized varchars. Will look at what I can add to support this.

FYI, v4.0.11 on MyGet allows you to specify a Custom SQL definition so you can use this for specifying a CHAR(N) column, e.g: https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/CustomSqlTests.cs#L65

Fredrick Lackey:

Thanks for following up.  I’ll go this route if I get desperate.  Any chance you could add this?  At least on SQL Server, the char data type can be faster and consume less space than the same size varchar.

The Custom SQL works fine for alternate definitions, added an example in today’s the release notes: https://github.com/ServiceStack/ServiceStack/wiki/Release-Notes#wiki-custom-field-declarations
Wont be adding individual attributes for non-default field definitions.