Set database collation in Entity Framework Code-First Initializer

后端 未结 8 1337
后悔当初
后悔当初 2020-12-01 12:26

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         


        
8条回答
  •  孤街浪徒
    2020-12-01 13:01

    It's simply not possible using current versions of EF (EF6). However, at least EF6+ can now work with already existent database. We've changed our deployment scenario such that the database is already created by our deployment script (incl. the default collation) and let EF6 work with the existing database (using the correct default collation).

    If you absolutely have to create the database inside your code and cannot use anything else than EF (e.g. you are not able to create the database using ADO.NET) then you have to go for seliosalex answer. It's the only solution we came up, however, see my comment, it is a lot of work to do it right.

提交回复
热议问题