一台机器上出现 EF4.1 错误,另一台机器上没有
我在一台电脑上收到此错误,但在另一台电脑上则没有。两者都连接到本地 SQLExpress 2008 R2 数据库,该数据库在两台计算机上是相同的。两台机器都有VS2010 SP1和EF4.1(包含在工具更新中)。这是一个在 Cassini 中运行的 MVC3 Web 应用程序项目:
[NotSupportedException:无法创建类型为“System.Collections.Generic.IEnumerable`1”的常量值。在这种情况下,仅支持原始类型(“例如 Int32、String 和 Guid”)。]
我一生都无法弄清楚为什么会出现这种情况 - 它发生在 Attach()< /code> 下面:
IQueryable<Tag> tags = db.Tags.Where(x => !tagIds.Contains(x.Id) && x.Questions.Any(y => y.Id == question.Id));
question.Tags.Attach(tags);
我能想到的唯一区别是一台机器是 32 位而另一台机器是 64 位,但我不知道如何确定这是否是问题所在。
有什么想法吗?
TIA
I am getting this error on one PC but not on another. Both are connecting to a local SQLExpress 2008 R2 database which is identical on both machines. Both machines have VS2010 SP1 and EF4.1 (included in the tools update). It is an MVC3 Web Application project running in Cassini:
[NotSupportedException: Unable to create a constant value of type 'System.Collections.Generic.IEnumerable`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.]
I can't for the life of me work out why this is the case - it happens at the Attach()
below:
IQueryable<Tag> tags = db.Tags.Where(x => !tagIds.Contains(x.Id) && x.Questions.Any(y => y.Id == question.Id));
question.Tags.Attach(tags);
The only difference I can think of is that one machine is 32-bit and the other 64, but I don't know how to determine if this is the problem for any reason.
Any ideas?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题的根源在于 x => !tagIds.Contains(x.Id) 因为“Contains”无法通过 EF 转换为 T-SQL。尝试搜索异常以获取更多信息。
The root of the problem would be the
x => !tagIds.Contains(x.Id)
as the "Contains" cannot be translated to T-SQL by EF. Try searching on the exception for more information.两个本地数据库中的数据不相同,这意味着
tagIds
在一台机器上返回 null,而在另一台机器上则不返回 null。该错误消息不是很有帮助,但这就是导致它的原因。在这种情况下使用
Contains
在 EF4 中是没问题的。The data in the two local databases was not the same, which meant that
tagIds
returned null on one machine and not on the other. The error message isn't very helpful but that was what caused it.Using
Contains
in this scenario is fine in EF4.