【发布时间】:2018-07-19 00:13:54
【问题描述】:
只是想抓住 EF。当我们使用 sql 时,我们经常在 in 子句中写入多个值
Select * from customer
Where countryCode in ('gb','us','fr')
我正在搜索如何使用 EF 和 LINQ 编写相同的查询。我找到了这些代码。
var countries= new[] {
new {Country=…, City=…, Address=…},
…
}
approach 1
------------
var result = locations.Where(l => keys.Any(k =>
k.Country == l.Country &&
k.City == l.City &&
k.Address == l.Address));
approach 2
------------
var result = from loc in Location
where keys.Contains(new {
Country=loc.Country,
City=loc.City,
Address=loc.Address
}
select loc;
告诉我如何在不使用多个包含关键字的情况下将下面的 sql 查询转换为 EF
Select * from customer
Where countryCode in ('gb','us','fr')
【问题讨论】:
-
请不要编辑您的问题的答案。相反,在重复的帖子上发布答案。
标签: c# entity-framework