更新时间: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);