Pulagara Murali

Pulagara Murali

  • NA
  • 43
  • 43.6k

NHibernate Projections

Nov 6 2012 2:19 AM

  _iCriteria = _session.CreateCriteria(typeof(Service));
 _iCriteria.SetProjection(Projections.ProjectionList()
                               .Add(Projections.Property("ServiceMasterId"), "ServiceMasterId")
                               .Add(Projections.Property("ServiceName"), "ServiceName")
                                .Add(Projections.Property("ServiceCode"), "ServiceCode")
                               .Add(Projections.Property("IsService"), "IsService")
                               .Add(Projections.Property("IsRenderable"), "IsRenderable")
                               .Add(Projections.Property("IsProfile"), "IsProfile")
                               .Add(Projections.Property("IsDefaultRenderOnRequest"), "IsDefaultRenderOnRequest")
                               .Add(Projections.Property("DepartmentDetails"), "DepartmentDetails")
                               .Add(Projections.Property("SectionDetails"), "SectionDetails"));
                        _iCriteria.SetResultTransformer(Transformers.AliasToBean(typeof(Service)));

Here I am writing projections on Service object. But Here "DepartmentDetails" and "SectionDetails" are  "many-to- one" to Service object.
how to write projection on Child collections means projections on many-to-one and bags?

Here ServiceMaster, DepartmentMaster and SectionMaster are Three tables. Below is the my oracle query.

SELECT SM.MASTER_ID AS SERVICEID,SM.NAME AS SERVICENAME ,
DM.MASTER_ID DEPTID,DM.NAME AS DEPTNAME,
SECM.MASTER_ID AS SECTIONID,SECM.NAME AS SECTIONNAME FROM SERVICEMASTER SM
INNER JOIN DEPARTMENTMASTER DM ON SM.DEPARTMENTID=DM.MASTER_ID
INNER JOIN SECTIONMASTER SECM ON SM.SECTIONID=SECM.MASTER_ID;

I need same result using NHibernate using projections


Can any one give me reply on This query?