Reputation: 2473
Code-First conventions are really throwing me for a loop. I am working with an existing database, so I am mixing new tables with existing tables. I'm using the EntityConfiguration class when I need to configure different mapping/relations, so lets say I have a Customer and an order. If conventions are not in-line, do I need to create two EntityConfiguration classes, one for each end? Is it yes..no..sometimes? I'm really confused here...
Thanks
Upvotes: 1
Views: 249
Reputation: 2622
Without knowing what your mappings look like its hard to say, but I would try something like this for a custom one-to-many mapping.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Order>()
.HasRequired(o => o.Customer)
.WithMany(c => c.Orders)
.HasForeignKey(o => o.CustomerId);
base.OnModelCreating(modelBuilder);
}
Upvotes: 1