rajesh Kumar
rajesh Kumar

Reputation: 65

Distinct Join in Nhibernate

I want two columns from two different tables using join. I am getting duplicate values. I tried .SetResultTransformer(Transformers.DistinctRootEntity) and .SetResultTransformer(new DistinctRootEntityResultTransformer()) but nothing helped me. In profiler i am getting query like:

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

I want query for distinct values.like: SELECT distinct job1_.DeptName as y0_, this_.refDeptId as y1_ FROM [Emp] this_ inner join [Dept] job1_ on this_.refDeptId=job1_.DeptId My query in nhibernate is:

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

Please help me...

Upvotes: 1

Views: 195

Answers (1)

jbl
jbl

Reputation: 15413

Is your a_list something like below (with aliases in case you want to Transform to DTO) ?

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

Upvotes: 1

Related Questions