4

I created a model in the edm designer (VS10) using "DbContext Entity Generator" as the generation item.

In the generated DbContext subclass, it overrode the constructor so I can't use it in the other partial class:

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

What's the proper way of initialize a database with model-first?

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632

2 Answers2

3

You could alter the T4 template that's being used for generating the DbContxt class. Then you could add the partial modifiers or methods that you want to use to initialize your context.

Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103
3

There is no automatic database initialization when using model first. You must generate SQL script from the model (use context menu in EDMX designer and choose Generate database from model) and execute it yourselves on existing database.

SetInitializer is only for code first.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670