Team Interceptor Solution
It is definitely possible, although itβs a little hack. You can modify the CREATE DATABASE command with a command interceptor. Il will intercept all the commands sent to the database, recognize the command to create the database based on the regular expression, and change the text of the command using sorting.
Before creating a database
DbInterception.Add(new CreateDatabaseCollationInterceptor("SQL_Romanian_Cp1250_CI_AS_KI_WI"));
Interceptor
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) {
Notes
Since the database is created with the correct sorting from the very beginning, all columns will automatically inherit this sorting, and after that you will not have ALTER.
Remember that this will affect the subsequent database creation that occurs within the application domain. This way you can remove the interceptor after creating the database.
Mathieu Renda 03 Mar. '17 at 10:41 2017-03-03 10:41
source share