且构网

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

如何将子实体映射子实体到父实体,而不在子实体中引入原语类型父链接器?

更新时间:2023-02-13 12:09:53

我不明白您为什么要使用流畅映射?您的模型应该按照默认约定进行映射。如果要使用流畅贴图对其进行贴图,请使用:

modelBuilder.Entity<Product>()
            .HasMany(x => x.ProductPriceList) // Product has many ProductPricings
            .WithRequired(y => y.Product)     // ProductPricing has required Product
            .Map(m => m.MapKey("ProductId")); // Map FK in database to ProductId column