如何删除实体框架中的外键引用
我正在更新由实体框架构建的模型。我从设计器中删除了一个实体,然后弹出一个错误“外键约束'FK_Table1_Table2'...没有为表Table2指定映射。现在我真的不想将Table2映射到实体中。我该怎么办清除 edmx 并避免此类错误?我可以将 Table1 中的外键映射到 int32 字段吗?谢谢
!
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!
I'm using EFv1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现实体框架设计器还有很多不足之处,因此我发现最好的方法是手动编辑 .edmx。
.edmx 文件包含 3 个主要部分,一个部分代表存储模型(数据库),一个部分代表概念模型,一个部分代表两个模型之间的映射
如果我理解正确的话,您已从概念模型中删除了 Table2 并且因此您应该在 EDMX 的概念方面删除与其相关的任何内容。 表 1 仍可能与您需要删除的表 2 存在关联。不幸的是,如果您使用设计器重新生成模型,对 .EDMX 文件的手动编辑将被覆盖。
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.
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
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. Chances are table 1 will still have an association to table 2 that you need to delete. Unfortunately manual edits to the .EDMX file will be overwritten if you ever use the designer to regenerate the model.