error 2016: Condition cannot be specified for Colu

2019-08-05 05:00发布

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

2条回答
【Aperson】
2楼-- · 2019-08-05 05:50

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!!

查看更多
Juvenile、少年°
3楼-- · 2019-08-05 05:51

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

hope that helps.

查看更多
登录 后发表回答