我有一个对象列表(位置)。每个位置可以有多个类别。我有一个整数列表(CategoryId's)。在此基础上我需要过滤的位置:如何筛选我需要多个动态筛选参数的列表
List<int> categoriesToLoad = new List<int>();
// fill list
var allLocations = locationRepository.GetLocations().Where(...
var filteredLocations = from m in model
where categoriesToLoad.Contains(m.LocationCategories.FirstOrDefault() == null ? -1 : m.LocationCategories.FirstOrDefault().PlaceCategoryId)
select m;
这仅适用于一类,我不知道如何解决代码比较附加到位置的所有类别。
您可以使用'Any' http://stackoverflow.com/a/1757244/381422 – xdumaine