Stellar Sword
Stellar Sword

Reputation: 6226

SQL Server foreign keys messing with entity framework model

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?

Upvotes: 1

Views: 604

Answers (1)

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65381

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.

Upvotes: 1

Related Questions