SQL Server外键搞乱实体框架模型 [英] SQL Server foreign keys messing with entity framework model

查看:130
本文介绍了SQL Server外键搞乱实体框架模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体框架模型,我注意到模型文件中的图表中缺少一个表,一个用户组表。这意味着我无法将其从标准SQL调用中修改为成为实体框架的一部分(即,为实体创建类文件)。



我可以在实体集下看到它,但不在图中。每次尝试添加时,它不会显示为在更新模型菜单中添加的选项。所以我从Entity集中删除它,然后我终于在'update model'中看到了。我补充说仍然不会出现在图表上(它只是将其作为实体集,但不会为其制作图)。



在沮丧之后,我想到有一些外键阻止它被添加。所以我去了我的sql manager,并从usergroup表中删除了任何外键。



所以现在,当我添加模型,它出现在图表中!是!但是,现在编译器错误3002说模型不匹配。 潜在的运行时违反表说映射不正确,但我不明白---没有映射,没有链接用户组任何东西。



为什么会发生这种情况?我检查了其他外键和映射属性,没有映射到用户组。这是Visual Studio 2010中的错误吗?

解决方案

可能是edmx文件的部分不同步或可能零件已损坏。



您可以尝试在文本编辑器中打开edmx文件,并检查是否有任何错误。



您还可以尝试删除该表,然后在文本编辑器中打开edmx文件,并确保已删除对该表的所有引用。



映射错误为不在表之间,它位于edmx文件的各个部分之间。


I have an entity framework model, and I noticed that one table, a usergroup table is missing from the diagrams in the model file. This meant I could not modify it from the standard SQL calls to become part of the entity framework (i.e., to make a class file for it with entities).

I can see it under "entity sets" but not in the diagram. Every time I try to add, it doesn't show it as an option to add in the "update model" menu. So I deleted it from Entity set, and then I finally saw it in 'update model'. I added it. Still won't show up on diagram (it just puts it as Entity Set, but doesn't make a diagram for it).

After getting frustrated with it, I figured there was some foreign keys preventing it from being added. So I went to my sql manager, and deleted any foreign key from usergroup table.

So now, when I add in the model, it appears in the diagram! YES!

BUT, now compiler error 3002 saying models don't match. "Potential runtime violation of table" saying the mapping is incorrect, but I don't understand---there is no mapping there, there is nothing linking usergroup to anything.

Why is this happening? I checked other foreign keys and mapping properties and nothing maps to usergroup. Is it a bug in Visual Studio 2010?

解决方案

It is probably that the sections of the edmx file are out of sync or maybe parts are corrupt.

You could try opening the edmx file in a text editor and check for any errors.

You could also try removing that table, then opening the edmx file in a text editor and make sure that all references to that table have been removed.

The mapping error is not between tables, it is between parts of the edmx file.

这篇关于SQL Server外键搞乱实体框架模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆