문제

I have a pre-existing database and Entity Framework 6 database-first model generated from it. I need to create the same database on a different host and/or database engine. I hoped I could use the same model as code-first, but OnModelCreating method of the generated DbContext seems to be protected from being used for code-first approach, it throws UnintentionalCodeFirstException. Generated models don't have any attributes applied too.

Is there any way to reuse my database-first model to create a database with the same schema? Or maybe there's an obvious and much simpler way to do it that I'm missing?

도움이 되었습니까?

해결책

If you just want to create the database you shouldn't need to touch the OnModelCreating method. You should be able to do this from the designer (right click on the designer surface and select "Generate Database From Model" and run the script) or if you want to do this from code do ctx.Database.Create() or use the CreateDatabaseIfNotExists initializer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top