NHibernate预测列表

时间:2013-01-28 11:57:36

标签: nhibernate nhibernate-criteria nhibernate-projections

我有以下情况:

StudentEnrolment实体包含Student,CourseOffering,Batch etc实体。 学生实体中包含名称(IList)列表。

我正在创建如下标准(用于获取StudentEnrolmentSummary类型的预测):

var studentEnrolmentSummaries = session.CreateCriteria<StudentEnrolment>("se")
                .CreateAlias("Student", "i")
                .CreateAlias("CourseOffering", "co")
                .SetProjection(Projections.ProjectionList()
                                   .Add(Projections.Property("StudentEnrolmentId"), "StudentEnrolmentId")
                                   .Add(Projections.Property("CourseOffering.CourseOfferingId"), "CourseOfferingId")
                                   .Add(Projections.Property("Batch"), "Batch")
                                   .Add(Projections.Property("StartDate"), "StartDate")
                                   .Add(Projections.Property("EndDate"), "EndDate")
                                   .Add(Projections.Property("Student.ContactId"), "StudentContactId")
                                   .Add(Projections.SubQuery(DetachedCriteria.For<Course>("c")
                                        .Add(Restrictions.EqProperty("c.CourseId", "co.Course.CourseId"))
                                        .SetProjection(Projections.Property("CourseType"))), "CourseType")


                                   //Trial:1
                                   //.Add(Projections.Property("i.Names"), "Names")

                                   //Trial:2
                                   //.Add(Projections.ProjectionList()
                                   //.Add(Projections.Property("i.Names"), "Names"))

                                   //Trial:3
                                   //.Add(Projections.SubQuery(DetachedCriteria.For<Individual>("i")
                                   //     .Add(Restrictions.EqProperty("se.Student.ContactId", "i.ContactId"))
                                   //     .SetProjection(Projections.Property("Names"))), "Names")

                )
                .Add(Restrictions.Eq("CourseOffering.CourseOfferingId", courseOfferingId))
                .SetResultTransformer(Transformers.AliasToBean<StudentEnrolmentSummary>())
                .List<StudentEnrolmentSummary>();

然而,上述试验中没有一项(作为试验1,2,3评论)起作用。

有人可以建议一个合适的解决方案吗?

提前致谢,

0 个答案:

没有答案