Search code examples
nhibernatenhibernate-mappingcollation

Set column collate in NHibernate mapping


I'm looking into NHibernate mapping and we are in a situation where we require to specify the collate on a specific column. Preferably during the mapping.

The idea is that after NHibernate creates the schema, it will look something like this:

CREATE TABLE [dbo].[Foo] (
    [Bar]        NVARCHAR (128) NULL **collate sql_latin1_general_cp1_cs_as**,
    [BarTwo]     NVARCHAR (max)
);

I'm currently using Fluent but an xml solution would be fine as well.


Solution

  • I found out that I can add the collate to the CustomSqlType. It does mean that I need to add always a CustomSqlType and therefore make the mapping database depended.

    .CustomSqlType("nvarchar(128) collate Latin1_General_CI_AS")
    

    But for now it seems to work. Anyone has another/better idea/proposition?