nhibernate地图类别包含前n名产品

nhibernate地图类别包含前n名产品,nhibernate,nhibernate-mapping,Nhibernate,Nhibernate Mapping,我有一个问题,那就是“类别类”包含了很多产品类。但是现在,我有一个CategoryService类,它将以相同的方式实现find IList,每个类别只包含前n个产品,而不是所有产品,我应该怎么做?给我一个选择,谢谢 代码列表: public class category { public int Id{get;set;} public int Categoryname{get;set;} public IList<Product> Products{ge

我有一个问题,那就是“类别类”包含了很多产品类。但是现在,我有一个CategoryService类,它将以相同的方式实现find IList,每个类别只包含前n个产品,而不是所有产品,我应该怎么做?给我一个选择,谢谢

代码列表:

 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...
}
公共类类别
{
公共int Id{get;set;}
public int Categoryname{get;set;}
公共IList产品{get;set;}
}
公共类产品
{
公共int Id{get;set;}
公共字符串ProductName{get;set;}
公共类别{get;set;}
等
}
然后创建一个域服务:

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;
   }
 }
公共类类别服务
{
专用ICategoryRepository类别存储库;
公共类别服务(ICategoryRepository类别存储库)
{
this.categoryRepository=categoryRepository;
}
公共IList FindAll()
{
IList类别;
categories=categoryRepository.FindAll();
//现在我需要categoryRepository查找所有类别,并且每个类别都包含top n产品,我应该怎么做;
退货类别;
}
}
var count=//这是你的最爱
session.QueryOver
.Fetch(category=>category.Product).Eager
.记(数)
.变压器使用(变压器.距离)
.List();

到目前为止,您尝试了什么?你的代码看起来像什么?帮助我们帮助你。谢谢!我的英语不好!好的,你想要怎样的结果?在
DTO
类中或作为
类别。TopProducts
?另外,你说的顶级产品是什么意思,这是按类别分组的产品?我想要一个结果作为Category.TopProducts,我使用Nhibernate作为ORM,并使用Automapper将域模型映射到DTO,你能告诉我ORM映射和CategoryService.FindAll()类应该做什么吗?
var count = // it's your top
session.QueryOver<Category>
.Fetch(category => category.Product).Eager
.Take(count)
.TransformUsing(Transformers.DistinctRootEntity)
.List();