2013-03-12 100 views
1

我想从两个不同的表中使用连接两列。我得到重复值。我试过.SetResultTransformer(Transformers.DistinctRootEntity)和.SetResultTransformer(new DistinctRootEntityResultTransformer()),但没有任何帮助。在探查我得到的查询,如:独特加入Nhibernate

SELECT job1_.DeptName as y0_, this_.refDeptId as y1_ FROM [Emp] this_ inner join [Dept] job1_ on this_.refDeptId=job1_.DeptId 

我想查询不同values.like:SELECT distinct job1_.DeptName as y0_, this_.refDeptId as y1_ FROM [Emp] this_ inner join [Dept] job1_ on this_.refDeptId=job1_.DeptId 我在NHibernate的查询是:

IList ListOfElements= (session 
    .CreateCriteria(typeof(EmpModel)) 
    .CreateCriteria("objEmpDeptId1", "job",NHibernate.SqlCommand.JoinType.InnerJoin) 
    .SetProjection(a_ProjectionList).List()); 

请帮我...

回答

1

是你的a_list如下所示(如果你想转换为DTO,使用别名)?

Projections.Distinct(Projections.ProjectionList() 
    .Add(Projections.Property("DeptName ").As("BeanDeptName")) 
    .Add(Projections.Property("refDeptId ").As("BeanDeptId"))