Linq to实体中多个国家/地区的lambda表达式
我有一个领域叫乡村。 现在我必须根据匹配的国家筛选记录 当我必须过滤单个国家的记录时,我使用lambda表达式,如下所示Linq to实体中多个国家/地区的lambda表达式,linq,lambda,linq-to-entities,Linq,Lambda,Linq To Entities,我有一个领域叫乡村。 现在我必须根据匹配的国家筛选记录 当我必须过滤单个国家的记录时,我使用lambda表达式,如下所示 string strCountry = "USA"; var data = entities.Documents.Where(p => p.Country == strCountry); 现在我有如下国家的名单。我想知道如何筛选这个国家名单的记录 List<string> strCountry = new CacheUser().GetUserCountr
string strCountry = "USA";
var data = entities.Documents.Where(p => p.Country == strCountry);
现在我有如下国家的名单。我想知道如何筛选这个国家名单的记录
List<string> strCountry = new CacheUser().GetUserCountry();
List strCountry=new CacheUser().GetUserCountry();
感谢您的回复
谢谢试试:
List<string> countries = ...;
var data = entities.Documents.Where(p => countries.Contains(p.Country));
列出国家=。。。;
var数据=实体.Documents.Where(p=>countries.Contains(p.Country));
这将导致SQL中出现“in”查询。但是,您应该意识到,一旦列表中有大量国家,这可能会失败。我想你不能用连接来代替?国家名单只在客户端知道