0
votes

While using EF to create a new solution/database, I am trying to set composite keys on the OnModelCreating method since its not possible to do this from the designer in a ModelFirst approach.

The thing is, after I make changes to the OnModelCreating(DbModelBuilder modelBuilder) method, if I have to make a change in my database and hit "generate database from model" it overrides anything I placed there, how can I avoid this?

Thank you

1
I can't believe that it's not possible to create a composite key in the model designer. Can't you just mark two properties of an entity as "EntityKey"?Slauma
not possible, it throws a bunch of errors :( it makes EF look so basic..Bryan Arbelo - MaG3Stican

1 Answers

0
votes

Make use of the IDatabaseInitializer interface, see this for details.

Also add the DatabaseInitializerForType key into appSettings