CodeFluent Entities And SQL Server Collation
Collations in Microsoft SQL Server control physical storage of character strings, and a point of interest is that using collations you control whether ‘m‘ is equal or not equal to ‘M‘.
For instance, say I have a table with a "Label" column containing the value "Car", if your current collation is case insensitive, running the following query will match our "Car" value:
where Label like ‘ca%’
Now if you modify your collation using this query:
ALTER TABLE [Test]
ALTER COLUMN [Label] nvarchar(256) COLLATE Latin1_General_CS_AI
And run the same query again, our "Car" value won’t match anymore as it is case sensitive.
Now back to CodeFluent Entities 🙂
In CodeFluent Entities, the SQL Server Producer provides attributes at project, entity and property levels to set your desired collation name.
<Label cfps:collationName="Latin1_General_CS_AI" />
Note: "cfps" corresponds to the SQL Server Producer namespace, declared on the Project element like ‘xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1"’
And this will generate the following code:
[Test_Label] [nvarchar] (256) COLLATE Latin1_General_CS_AI NULL
As mentioned, you can also specify it at project or entity level so it’s automatically added for all appropriate properties:
This will generate the following in your table script:
[Test_Label] [nvarchar] (256) COLLATE Latin1_General_CS_AI NULL,
[Test_Name] [nvarchar] (256) COLLATE Latin1_General_CS_AI NULL,