【发布时间】:2014-03-16 08:31:39
【问题描述】:
我有以下 Linq 查询
public static List<string> selectedLocations = new List<string>();
// I then populate selectedLocations with a number of difference strings, each
// corresponding to a valid Location
viewModel.people = (from c in db.People
select c)
.OrderBy(x => x.Name)
.ToList();
// Here I'm basically filtering my dataset to include Locations from
// my array of selectedLocations
viewModel.people = from c in viewModel.people
where (
from a in selectedLocations
where a == c.Location.Name
select a
).Any()
select c;
这非常有效,因为每个 Person 记录都可以有一个 Location。
我的问题是,如果 Person 可以与 Location 建立一对多关系,我该如何更改此查询?以一个人可以有 2 个位置为例,我需要将此行更改为什么?
where a == c.Location.Name
谢谢!
【问题讨论】: