4

我需要使用 LINQ 从字符串列表中比较并获取匹配值。看看我的代码。

代码

Split = Id.Split(',');
List<string> uids = new List<string>(Split);
var model = (from xx in Db.ItemWeedLogs
                where xx.ItemNo == uids   
                // I need to pass a string list to extract the matching record.
                select xx).ToList();
4

3 回答 3

7

试试这个 :

var model = (from xx in Db.ItemWeedLogs
                     where uids.Contains(xx.ItemNo)
                     select xx).ToList();
于 2012-12-11T13:14:15.427 回答
2

尝试:

where uid.contains(xx.ItemNo)
于 2012-12-11T13:14:38.873 回答
2

我认为这更快更清晰。

var model = Db.ItemWeedLogs
              .Join(Id.Split(','), di => di.ItemNo, si => si, (d, s) => new {d})
              .ToList();
于 2012-12-11T13:27:21.590 回答