我有一个数据库,其中许多表都有 createBy/modifiedBy 列,这些列是用户表的外键。当我从数据库更新模型时,它会为所有这些关系生成导航属性。 User 实体最终有数十个集合来导航这些关系。
当我从数据库更新模型时,我可以选择“在模型中包含外键列”。如果取消选中它,我将获得导航属性,但不会获得外键字段。有没有办法生成相反的内容,保留外键字段,但不添加导航属性?
我是实体框架的新手,所以如果我的问题凸显了我的无知,我深表歉意。
I have a database where many of the tables have createdBy/modifiedBy columns that are foreign keys into a User table. When I update my model from the database, it generates navigation properties for all of these relationships. The User entity ends up with dozens of collections to navigate these relationships.
When I update the model from the database, I have the option to "Include foreign key columns in the model". If I un-check it, I get the navigation properties, but not the foreign key fields. Is there a way to generate the opposite, keep the foreign key fields, but don't add the navigation properties?
I'm new to Entity Framework, so I apologize if my question highlights my ignorance.
发布评论
评论(2)
不,没有这样的选项。您必须手动从
User
实体中删除导航属性。一旦您从数据库更新模型,它就不应该再次添加它们。No there is not such option. You must manually delete navigation properties from
User
entity. It should not add them again once you update model from database.这是一个痛苦的情况 - 目前,当我从数据库更新模型并添加新表时,所有讨厌的导航属性都会回来。还有其他人知道如何删除所有 FK 引用和导航属性吗?
我找到的最接近的答案是在此处自定义 T4 代码生成: http://blogs.msdn.com/b/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx
This is a painful situation - currently when I update the model from db and add a new table all the pesky navigation properties come back. Does anyone else have an idea of how to strip out all the FK references and Navigation properties?
The closest answer I have found is customizing the T4 code generation here: http://blogs.msdn.com/b/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx