错误2016:列成员不能指定条件 [英] error 2016: Condition cannot be specified for Column member

查看:125
本文介绍了错误2016:列成员不能指定条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在这里遇到的问题在这里描述得很好...


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



这基本上发生了当外键指向另一个表的主键时,但如果我将 StoreGeneratedPattern 取消为 Identity ,然后尝试在身份字段中插入一个值



编辑



所以,似乎是EF4在主键设置为 StoreGeneratedPattern =Identity时无法处理空关系。如果我创建一个指向此主键的FK,并使其为空(有效地创建一个 0 ... M 关系),那么它会抛出此编译错误。 >

删除 StoreGeneratedPattern =Identity修复问题,但会导致问题elseware
如果外键是设置为不可为空

解决方案

所以,我在本周与DevWeek的某人交谈,我们设法找到答案...



基本上,如果我在一个实体上有一个可空的外键关系,并且实际的fk没有被映射到一个标量属性,那么它会引起一个摇摆。如果fk不为空,那么它不必映射到标量属性,它只能在关联中映射(这是我期望的)。但是,当模型生成时,EF给了我包含FK列的选择 - 我对此表示不谢谢 - 所以没有添加这个标量属性...所以编译失败。多么奇怪!!


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

解决方案

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

这篇关于错误2016:列成员不能指定条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆