【发布时间】:2014-03-16 18:10:58
【问题描述】:
对这个问题的跟进:Changing a linq query to filter on many-many
我有以下 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 c.Locations.Any(o => o.Name == a)
select a
).Any()
select c;
如何修改查询,以便它还返回根本没有设置位置的人?
【问题讨论】: