I have a database I drop each time I start a debug server, and then recreate it. The problem is that
EnsureCreatedAsync does not allow to define collation.
Here is a really ugly workaround:
await db.Database.EnsureDeletedAsync();
var builder = new SqlConnectionStringBuilder(db.Database.GetDbConnection().ConnectionString) { InitialCatalog = "master" };
builder.Remove("AttachDBFilename");
using (var connection = new SqlServerConnection(new DbContextOptionsBuilder().UseSqlServer(builder.ConnectionString).Options, logger))
{
connection.Open();
using (var command = new SqlCommand())
{
command.Connection = connection.DbConnection as SqlConnection;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "CREATE DATABASE [mvcApiTest] COLLATE Finnish_Swedish_CI_AS;";
await command.ExecuteNonQueryAsync();
}
}
await db.Database.EnsureCreatedAsync();
I have a database I drop each time I start a debug server, and then recreate it. The problem is that
EnsureCreatedAsyncdoes not allow to define collation.Here is a really ugly workaround: