I'm migrating my MVC5 app to MVC6. Currently I'm using two conventions
public class RentABikeDbContext : DbContext
{
...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}
}
However it looks like in MVC6/EF7 there is no Conventions property on the new Microsoft.Data.Entity.ModelBuilder class. What is the proper EF7 way to specify conventions?
Entity Framework 7 does not have any built-in pluralization, so nothing to remove there, and Cascade delete is not yet implemented https://github.com/aspnet/EntityFramework/issues/333
Iterate thru all entities, get the foreign keys, and set them to Delete Restricted:
foreach (var relationship in builder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}