Is there any way to configure what collation to use when EF creates the database?
Or is there some kind of hook to set the collation after the database is created but before the tables are created?
I solved the issue by creating the DB myself. The base class is then creating the tables into the empty DB:
public class MyInitializer : CreateDatabaseIfNotExists<MasterDataModel>
{
public override void InitializeDatabase(MasterDataModel context)
{
if(!context.Database.Exists())
{
using (SqlConnection connection = new SqlConnection("YourConnectionString"))
{
connection.Open();
using(SqlCommand command = new SqlCommand(string.Format("CREATE DATABASE {0} COLLATE Latin1_General_CI_AS", "NameOfDatabase"), connection))
{
command.ExecuteNonQuery();
}
}
SqlConnection.ClearAllPools();
}
base.InitializeDatabase(context);
}
}