Multiple foreign keys pointing to same table in Entity Framework 4.1 code first

前端 未结 2 1214
花落未央
花落未央 2020-12-14 09:42

I\'m stuck at trying to write the Entity Framework 4.1 code first model for the following DB relationship.

Here is a visual of the relationship.

2条回答
  •  天涯浪人
    2020-12-14 10:15

    This blog has the example using Fluent API configurations.

    Multiple foreign keys within same table using CodeFirst Entity Framework and Fluent API

    modelBuilder.Entity().HasOptional(b => b.PrimaryContact)         
                .WithMany(a => a.PrimaryContactFor).HasForeignKey(b=>b.PrimaryContactID);
    

提交回复
热议问题