I want to set the default collation for a database, when Entity Framework Code First creates it.
I\'ve tried the following:
public class TestInitiali
I have had the same problem a while ago. Possible solutions:
Seed()
method
but you can change the collation of individual columns for a table
(NOTE: there is no such thing as table collation, it does relate to
column in a table). You will have to change each column's collation
separately.Up()
method.As you are using the Seed()
method, I would suggest the following (modify as appropriate) within the Seed()
method:
context.Database.ExecuteSqlCommand(
@"ALTER TABLE MyTable ALTER COLUMN MyColumn NVARCHAR(max) COLLATE MyCollation NOT NULL");
Hope that helps.
EF 5 now supports creating missing tables in an existing database with Code First, so you can create an empty database and set the collation correct, before running an CF on it.