Entity Framework Contains/In Clause with SQLCE
I am trying to select items from an SQLCE table, where a field exists in a string array. This is easy in SQL with:
SELECT *
FROM TableX
WHERE SomeField In
([comma delimited array values]);
I am having a difficult time transposing this to LINQ. The following would logically work, but it is receiving this error: LINQ to Entities does not recognize the method 'Boolean Contains[String](System.Collections.Generic.IEnumerable`1[System.String], System.String)' method, and this method cannot be translated into a store expression.
var result = from c in DB.TableX
where someStringArray.Contains(c.SomeField)
select c;
Please let me know if anyone has any ide开发者_高级运维as or advice.
Thanks!
Update:
The following, reccomended below, throws a NotSupportedException, with error message, where class X is the class calling the enumeration: Unable to create a constant value of type 'NamespaceX.ClassX'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
var result = from c in DB.TableX
where someStringArray.Any(s => s == c.SomeField)
select c;
try
var result = from c in DB.TableX
where someStringArray.Any(s => s == c.SomeField)
select c;
Please mark as answer if this solves your problem.
精彩评论