Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
nhibernate使用另一个对象列表筛选列表_Nhibernate_Linq To Objects_Linq To Nhibernate - Fatal编程技术网

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;}
[...]
我有两个班级的名单

  • 列表包含我的搜索结果
  • 列表<品牌>包含品牌列表
我的目标是删除ResultProduct中不再存在的所有品牌。(与其他标准一起)

我该怎么做

编辑:

谢谢佩克托夫的回答。 我想删除所有没有产品的品牌

我找到了另一个可行的解决方案

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))//仅返回产品列表中未显示的品牌

我找到了另一个解决方案,我编辑了这个问题。什么样的解决方案最适合你?我不认为有什么大的区别。我找到了另一个解决方案,我编辑了这个问题。什么样的解决方案最适合你?我不认为有什么大的区别。