【发布时间】:2012-01-05 08:51:48
【问题描述】:
我正在尝试动态构建 LINQ where 语句,但在尝试使用列表中的 contains 方法编写 IN 语句时遇到问题。
这是我的代码:
IQueryable<Customer> customers =
(from cus in objectCustomer
select cus); \\objectCustomer is all customers
//List of customer ID's passed into the method.
string[] sCustomerIDs = (string[])DictionaryParameters["CustomerIDs"];
customers = customers.Where(c => c.Assets.Any(a => sAssetIDs.Contains(a.UN_Asset.ToString())));
return customers.Cast<T>().ToList();
运行返回线时,我收到以下错误: LINQ to Entities 无法识别方法“System.String ToString()”方法,并且该方法无法转换为存储表达式。
有什么想法吗?如果我将 IQueryable 更改为 IEnumerable 以查询运行,但我需要使用 IQueryable,因为我正在使用实体框架,并且 IEnumerable 在我的过滤器发生之前返回所有记录。
非常感谢。
【问题讨论】:
标签: linq c#-4.0 dynamic entity-framework-4 contains