2012-08-09 29 views
1

如何將Linq寫入實體以製作與SQL Server中的where子句類似的where子句?問題是我需要搜索的字段是可空的int。我有以下代碼,但它返回「無法創建類型爲'System.Collections.Generic.List`1'的常量值,只支持基本類型(如Int32,String和Guid)在這方面。「Linq中針對可空字段的In子句

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 
     { 
      ... 
     } 
    ); 
} 
+0

哪一行出現錯誤? – 2012-08-09 23:02:54

+1

您可能必須執行'w.contact_id.Value' – 2012-08-09 23:19:11

回答