我有一個對象列表(位置)。每個位置可以有多個類別。我有一個整數列表(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