且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何解决“多重性在“角色”中无效错误?

更新时间:2021-10-29 10:05:40

尝试这个

public class Product : Entity
{
    public Retailer Retailer { get; set; }
    public int RetailerId { get; set; }
}

使用此配置(您没有定义外部存储零售商针对产品)

With this configuration (you didn't have a foreign key defined to store the RetailerId against the Product)

modelBuilder.Entity<Product>()
    .HasRequired(r => r.Retailer)
    .WithMany(p => p.Products)
    .HasForeignKey(p => p.RetailerId);