How to call Database.SetInitializer for a model first?

I created the model in edm-designer (VS10), using the "DbContext Object Generator" as a generation element.

In the generated DbContext subclass, it overrides the constructor, so I cannot use it in another partial class:

public EntitiesContainer() : base("name=EntitiesContainer") { this.Configuration.LazyLoadingEnabled = false; } 

What is the correct way to initialize a database with the first model?

+4
source share
2 answers

You can modify the T4 template that is used to create the DbContxt class. You can then add partial modifiers or methods that you want to use to initialize your context.

+3
source

When using the model for the first time, there is no automatic database initialization. You must generate the SQL script from the model (use the context menu in the EDMX designer and select "Create database from model") and execute it yourself on the existing database.

SetInitializer is for code only.

+3
source

Source: https://habr.com/ru/post/1382200/


All Articles