当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Linq Query to Compare with List of string values

问题描述:

I need to compare and get the matching values from a string list with LINQ. Have a look at my code.

Code

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();

网友答案:

Try this :

var model = (from xx in Db.ItemWeedLogs
                     where uids.Contains(xx.ItemNo)
                     select xx).ToList();
网友答案:

Try:

where uid.contains(xx.ItemNo)
网友答案:

I think this is much more faster and clear.

var model = Db.ItemWeedLogs
              .Join(Id.Split(','), di => di.ItemNo, si => si, (d, s) => new {d})
              .ToList();
分享给朋友:
您可能感兴趣的文章:
随机阅读: