nhibernate使用另一个对象列表筛选列表
我正在研究一个多方面的引擎 我有两种类型的课程:nhibernate使用另一个对象列表筛选列表,nhibernate,linq-to-objects,linq-to-nhibernate,Nhibernate,Linq To Objects,Linq To Nhibernate,我正在研究一个多方面的引擎 我有两种类型的课程: ResultProduct public int Id { get; set; } public int Name { get; set; } public int Brand { get; set; } [...] 及 品牌 公共int Id{get;set;} 公共int名称{get;set;} 公共IList乘积{get;set;} [...] 我有两个班级的名单 列表包含我的搜索结果 列表包含品牌列表 我的目标是删除ResultP
ResultProduct
public int Id { get; set; }
public int Name { get; set; }
public int Brand { get; set; }
[...]
及
品牌
公共int Id{get;set;}
公共int名称{get;set;}
公共IList乘积{get;set;}
[...]
我有两个班级的名单
- 列表
包含我的搜索结果 - 列表<品牌>包含品牌列表
brands = (from brand in brands
where (from res in resultSearch select res.Brand.IdBrand).Contains(brand.IdBrand)
select brand).ToList<Brand>();
brands=(来自品牌中的品牌
其中(从resultSearch中的res选择res.Brand.IdBrand)。包含(Brand.IdBrand)
选择品牌);
我认为您的解决方案将带来更好的性能,您认为如何?我不确定我是否完全理解这个问题,我假设您希望删除品牌列表中的所有项目,因为resultProducts中没有具有该品牌ID的项目,而不考虑品牌类别中的产品列表 如果是这种情况,您可以像这样使用RemoveAll方法:
List<ResultProducts> products;
List<Brands> brands;
brands.RemoveAll(x=> !products.Exists(y=>y.brand == x.Id)); //returns only brands that don't appear in the products list
列出产品;
列出品牌;
brands.RemoveAll(x=>!products.Exists(y=>y.brand==x.Id))//仅返回产品列表中未显示的品牌
我不确定我是否完全理解了这个问题,我假设您想删除品牌列表中的所有项目,而不考虑品牌类别中的产品列表,因为在resultProducts中没有具有该品牌ID的项目
如果是这种情况,您可以像这样使用RemoveAll方法:
List<ResultProducts> products;
List<Brands> brands;
brands.RemoveAll(x=> !products.Exists(y=>y.brand == x.Id)); //returns only brands that don't appear in the products list
列出产品;
列出品牌;
brands.RemoveAll(x=>!products.Exists(y=>y.brand==x.Id))//仅返回产品列表中未显示的品牌
我找到了另一个解决方案,我编辑了这个问题。什么样的解决方案最适合你?我不认为有什么大的区别。我找到了另一个解决方案,我编辑了这个问题。什么样的解决方案最适合你?我不认为有什么大的区别。