开发者

error 2016: Condition cannot be specified for Column member

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 开发者_如何学Pythonfield

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


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


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

  • This was an issue in VS2010 beta 2 -http://social.msdn.microsoft.com/Forums/en-NZ/adonetefx/thread/01da2279-56db-4642-a7cc-f94a8871f230
  • Your using VS 2010 RC, but the model was created in beta 2 -- in this case just delete the files and start from scratch.

hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜