EF4.1 error on one machine and not on another
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 mach开发者_如何学运维ine 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
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.
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.
精彩评论