Nhibernate通过多列连接表

时间:2011-11-04 12:47:21

标签: nhibernate fluent-nhibernate

我对NHibernate查询有以下问题。

一张表

LearnerDocuments :
    LearnerNumber
    CandidateNumber
    ....

其他表格

LearnerRegistration :
    LearnerId
    LearnerNumber
    ....

最后一个

Learner : 
    LearnerId 
    LearnerName 
    ....

LearnerDocumentsLearnerRegistration之间的关系不存在。

如何编写一个查询,以获取LearnerRegistration的所有LearnerDocuments

1 个答案:

答案 0 :(得分:0)

 criteria.CreateCriteria(typeof(LearnerRegistration), "av")
                    ......

                    .Add(Restrictions.IsNotNull("RegistrationNumber"))                    
                    .Add(Subqueries.PropertyIn("l.Id", detachedCriteria))

                 ;


            var candidate = DetachedCriteria.For<LearnerDocuments>("sd")
                        .SetProjection(Projections.ProjectionList()
                        .Add(Projections.Property("sd.CandidateNumber"))
                        .Add(Projections.Property("sd.RegistrationNumber")))
                        .Add(Restrictions.EqProperty("sd.CandidateNumber", "l.LearnerNumber") 
                        && Restrictions.EqProperty("sd.RegistrationNumber", "lr.RegistrationNumber")
                        );

            var proj = Projections.Conditional(Subqueries.Exists(candidate),Projections.Constant(true),Projections.Constant(false));