Entity framework 4 用于导航属性的两种方式的Fluent API 班级 问题
注意属性Entity framework 4 用于导航属性的两种方式的Fluent API 班级 问题,entity-framework-4,ef-code-first,fluent,fluent-interface,Entity Framework 4,Ef Code First,Fluent,Fluent Interface,注意属性类别和产品类型 关系是一(ProductType)对多(ProductCategory),但是,ProductCategory与单个ProductType关联 在我的数据库中,它正在创建两个FK!! 对于这种情况,配置(使用FluentAPI)将如何进行 谢谢 HasMany(p => p.Categories) .WithRequired(c => c.ProductType) // specify inverse navigation property here
类别
和产品类型
关系是一(ProductType)对多(ProductCategory),但是,ProductCategory
与单个ProductType
关联
在我的数据库中,它正在创建两个FK!!
对于这种情况,配置(使用FluentAPI)将如何进行
谢谢
HasMany(p => p.Categories)
.WithRequired(c => c.ProductType) // specify inverse navigation property here
.WillCascadeOnDelete(false);
如果在WithRequired
EF中省略导航属性的lambda,则假定Category.ProductType
属于另一个关系-这就是数据库表中第二个外键的原因
HasMany(p => p.Categories).WithRequired().WillCascadeOnDelete(false);
HasMany(p => p.Categories)
.WithRequired(c => c.ProductType) // specify inverse navigation property here
.WillCascadeOnDelete(false);