Entity Framework Code First:
Suppose I want to create table relationships, where is the good place to put code in?
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<table1>().HasMany(i => i.AllowedDestinations).WithMany(d => d.something)
......
Or other place other than OnModelCreating?
You can create a class called “MYEntityConfiguration” (where MyEntity is the type of entity you are trying to configure) and inherit from the EntityTypeConfiguration<> type found in Entity Framework.
For example….
and the corresponding configuration file….
Then in your DBContext… OnModelCreating…
That will keep your configurations nice and contained… I found it to be the best way.