简体   繁体   English

如何在实体框架中删除外键引用

[英]How To Remove Foreign Key Reference In Entity Framework

I'm updating my model which is built by entity framework. 我正在更新由实体框架构建的模型。 I removed a entity from the designer and then there pops up a error said "Foreign key constraint 'FK_Table1_Table2' ... no mapping specified for the table Table2. Now I really don't want to map Table2 into entities. What should I do to clear the edmx and avoid such error? Can I just map the foreign key in Table1 into a int32 field? Thanks! 我从设计器中删除了一个实体,然后弹出一个错误消息:“外键约束'FK_Table1_Table2'...没有为表Table2指定映射。现在我真的不想将Table2映射到实体中。我该怎么办清除edmx并避免此类错误?我可以只将Table1中的外键映射到int32字段中吗?

I'm using EFv1. 我正在使用EFv1。

I've found the Entity Framework designer leaves a lot to be desired so I found the best way is to edit the .edmx by hand. 我发现Entity Framework设计器还有很多不足之处,所以我发现最好的方法是手动编辑.edmx。

The .edmx file contains 3 main sections, one which represents the storage model (database), one which represents the conceptual model and one section which represents the mapping between the two models .edmx文件包含3个主要部分,一个代表存储模型(数据库),一个代表概念模型,一个代表两个模型之间的映射

If I understand correctly, you have removed Table2 from the conceptual model and so you should remove anything related to it in the conceptual side of the EDMX. 如果我理解正确,那么您已经从概念模型中删除了Table2,因此应该在EDMX的概念方面删除与其相关的所有内容。 Chances are table 1 will still have an association to table 2 that you need to delete. 表1仍可能与您需要删除的表2有关联。 Unfortunately manual edits to the .EDMX file will be overwritten if you ever use the designer to regenerate the model. 不幸的是,如果您曾经使用设计器来重新生成模型,则对.EDMX文件的手动编辑将被覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM