我对NHibernate查询有以下问题。
一张表
LearnerDocuments :
LearnerNumber
CandidateNumber
....
其他表格
LearnerRegistration :
LearnerId
LearnerNumber
....
最后一个
Learner :
LearnerId
LearnerName
....
LearnerDocuments
和LearnerRegistration
之间的关系不存在。
如何编写一个查询,以获取LearnerRegistration
的所有LearnerDocuments
?
答案 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));