How do I create a primary key using two foreign keys in Entity Framework 5 code first?

我的未来我决定 提交于 2019-12-06 01:31:53

I figured it out! Add this HasMany to the foreign entity configs:

public Entity2Config : EntityTypeConfiguration<Entity2>
{
    HasMany(x => x.Entity1s)
        .WithRequired(x => x.Entity2)
        .HasForeignKey(x => x.Entity2_Id);
}

public Entity3Config : EntityTypeConfiguration<Entity3>
{
    HasMany(x => x.Entity1s)
        .WithRequired(x => x.Entity3)
        .HasForeignKey(x => x.Entity3_Id);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!