SQL Server foreign keys messing with entity framework model

筅森魡賤 提交于 2019-12-11 07:28:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5160265/sql-server-foreign-keys-messing-with-entity-framework-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!