views:

250

answers:

3

I am having some issues with Entity Framework in VS2010

The problem I'm getting is described very well here...

http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/cacf6a76-09a8-4c90-9502-d8b87c2f6bea

It's basically happening when a Foreign key is pointed at the primary key of another table...but if I take off the StoreGeneratedPattern as "Identity", then it tries to insert a value into the identity field

** EDIT So, what it seems to be is that EF4 can't handle a null relationship when the primary key is set to StoreGeneratedPattern="Identity". If I create a FK pointing to this primary key, and make it nullable (effectively creating a 0...M relationship), then it throws this compilation error.

Removing StoreGeneratedPattern="Identity" fixes the issue, but causes issues elseware It works if the foreign key is set to not nullable

A: 

So, I spoke with someone at DevWeek this week, and we managed to find the answer...

Basically, if I have a nullable foreign key relationship on an entity, and the actual fk isn't mapped to a scalar property, then it throws a wobbly. If the fk is not null, then it doesn't have to be mapped to a scalar property, it can just be mapped in the association (which is what I'd expect). But EF gave me the choice to include FK columns when the model was generated - to which I said no thank you - so it didn't add this scalar property...and so failed the compilation. How very strange!!

Paul
A: 

I've come across this error in a few situations ....

hope that helps.

EBarr
A: 

IP,

Thanks for pointing me back to my own post. :) I just ran into this same issue on another database, so I started searching again. Your solution worked.

JAGlick