Você só consegue isso se definir o COLLATION
da coluna (ou da tabela, ou do banco) antes. Há algumas formas de se fazer isso.
Uma delas é definindo um inicializador de base, assim:
public class CollationInitializer : CreateDatabaseIfNotExists<MeuContexto>
{
public override void InitializeDatabase(MeuContextocontext)
{
if(!context.Database.Exists())
{
using (SqlConnection connection = new SqlConnection("DefaultConnection"))
{
connection.Open();
using(SqlCommand command = new SqlCommand(string.Format("CREATE DATABASE {0} COLLATE Latin1_General_CI_AI", "MinhaBaseDeDados"), connection))
{
command.ExecuteNonQuery();
}
}
SqlConnection.ClearAllPools();
}
base.InitializeDatabase(context);
}
}
E:
public class MeuContexto: DbContext
{
public MeuContexto() : base("DefaultConnection", throwIfV1Schema: false)
{
Database.SetInitializer(new CollationInitializer<MeuContexto>());
if(!Database.Exists())
{
Database.Initialize(true);
}
}
}
Outra é definindo um interceptador de migrações para definir o COLLATION
na hora em que o banco está sendo atualizado:
public class CreateDatabaseCollationInterceptor : IDbCommandInterceptor
{
private readonly string _collation;
public CreateDatabaseCollationInterceptor(string collation)
{
_collation = collation;
}
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { }
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
// Apenas para SQL Server
if (Regex.IsMatch(command.CommandText, @"^create database \[.*]$"))
{
command.CommandText += " COLLATE " + _collation;
}
}
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { }
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { }
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { }
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { }
}