2012-04-10 5 views
0

質問があります。「カテゴリクラス」には多くの製品クラスが含まれています。しかし、今、私はすべての製品のすべてではなく、トップnを含むすべてのカテゴリーで同じ縫合でIListを実装するCategoryServiceクラスを持って、何をすべきですか?ありがとう!nhibernateマップカテゴリにはトップn製品が含まれています

コードリスト:

public class CategoryService 
{ 
    private ICategoryRepository categoryRepository; 

    public CategoryService(ICategoryRepository categoryRepository) 
    { 
    this.categoryRepository=categoryRepository; 
    } 

    public IList<Category> FindAll() 
    { 
    IList<Category> categories; 
    categories=categoryRepository.FindAll(); 

    //and now i need categoryRepository find all category ,and every category contains top n product, what should i do; 

    return categories; 
    } 
} 
+0

あなたがこれまでにしようとしているもの:

public class category { public int Id{get;set;} public int Categoryname{get;set;} public IList<Product> Products{get;set;} } public class Product { public int Id{get;set;} public string ProductName{get;set;} public Category Category{get;set;} etc... } 

は、ドメインサービスがありますか?あなたのコードはどのように見えますか?私たちがあなたを助けるのを助けてください。 – Rippo

+0

ありがとう!私の英語は良くありません! – alien

+0

OK、結果はどのようにしたいですか? 'DTO'クラスや' Category.TopProducts'のようなものですか?また、TOP製品が何を意味しているのですか?これはグループ化された製品ですか? – Rippo

答えて

0
var count = // it's your top 
session.QueryOver<Category> 
.Fetch(category => category.Product).Eager 
.Take(count) 
.TransformUsing(Transformers.DistinctRootEntity) 
.List(); 
関連する問題