2011-05-26 2 views
1

私はマルチファセットエンジンで作業しています。nhibernateリストを別のオブジェクトリストでフィルタリングする

ResultProduct 
public int Id { get; set; } 
public int Name { get; set; } 
public int Brand { get; set; } 
[...] 

Brand 
public int Id { get; set; } 
public int Name { get; set; } 
public IList<Product> Product { get; set; } 
[...] 

私がきた両方のクラスの一覧:

私は、クラスの2種類をしました。

  • リスト< ResultProduct>には検索結果が含まれています。
  • リスト<ブランド>ブランドのリストが含まれています。

私の目的は、これ以上ResultProductにないブランドをすべて削除することです。 (他の基準で)。

どうすればいいですか?

編集:あなたの答えのための

ありがとうpektov。 商品がないすべてのブランドを削除したいと考えています。

私は別の解決策を見つけました。

brands = (from brand in brands 
    where (from res in resultSearch select res.Brand.IdBrand).Contains(brand.IdBrand) 
    select brand).ToList<Brand>(); 

あなたのソリューションはパフォーマンスが向上すると思いますが、どう思いますか?

答えて

1

私は質問を正確に理解しているかわかりません。あなたは魔女のためのブランドリストのすべてのアイテムを削除したいと思っていますが、result.Productsはそのブランドではありません。ブランドのクラス

その場合は、次のような方法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 
+0

を私は別の解決策を見つけ、私は質問を編集しました。どのような解決策があなたに最適ですか? –

+0

大きな違いはないと思います。 –

関連する問題