Mike Barlow - BarDev
Mike Barlow - BarDev

Reputation: 11267

Entity Framework Code First - Change Table Column Collation

I'm using Entity Framework CTP5 and Code First. I need to change the Collation for a specific column in SQL Server. I believe the default collation is SQL_Latin1_General_CP1_CI_AS, but I need to change this one column colllation to SQL_Latin1_General_CP1_CS_AS (Case Sensitive).

Is there a way to use ModelBuilder in Code First to change a specific column collation?

BarDev

Upvotes: 14

Views: 10508

Answers (2)

Tod
Tod

Reputation: 2524

Some years later:

modelBuilder.Entity<Order>().Property(c => c.Name).UseCollation("SQL_Latin1_General_CP1_CS_AS");

Upvotes: 3

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

Model builder doesn't allow this but you can create custom database initializer and execute ALTER TABLE command. The example will be the same as this one creating custom index.

Upvotes: 14

Related Questions