实体关系 Has With ForeignKey
一对一 .HasRequired .WithMany .HasForeignKey
一对多 .HasMany .WithRequired .HasForeignKey
多对多 .HasMany .WithMany MapLeftKey,MapRightKey,ToTable
多对多(会自动建立一个mapping表 叫ProductRetailer)
HasMany(m => m.Retailers).WithMany().Map(m =>
{
m.ToTable("ProductRetailer");
m.MapLeftKey("ProductId");
m.MapRightKey("RetailerId");
});
多对一
HasMany(m => m.Images).WithRequired(m => m.Product).HasForeignKey(m=>m.ProductId);