Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 4 用于导航属性的两种方式的Fluent API 班级 问题_Entity Framework 4_Ef Code First_Fluent_Fluent Interface - Fatal编程技术网

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);