【发布时间】:2012-08-07 05:57:09
【问题描述】:
如何编写 Linq to Entities 以创建类似于 SQL Server 中的 where in 子句?问题是我需要搜索的字段是可为空的 int。
我有以下代码,但它返回“无法创建类型为 'System.Collections.Generic.List`1' 的常量值。仅支持原始类型('例如 Int32、String 和 Guid')这个上下文。”
public IList<WantedInfoView> GetWanted(string idList)
{
List<int> contactIDList = new List<int>();
contactIDList = idList.Split(',').Select(n => int.Parse(n)).ToList();
IEnumerable<WantedInfoView> wantedList = (
from w in db.Wanteds
where contactIDList.Contains(w.contact_id)
select new WantedInfoView
{
...
}
);
}
【问题讨论】:
-
哪一行出现错误?
-
你可能需要做
w.contact_id.Value
标签: c# linq entity-framework nullable contains