尝试编写流畅的查询以完成以下操作:查找为同一学生提供的服务,在同一天但使用不同的代码。 sql查询看起来像:
select * from [Service] t1
where exists (
select
*
from [Service] t2
where
t1.StudentId = t2.StudentId and
t1.ServiceDate = t2.ServiceDate and
t1.ProcedureCodeId <> t2.ProcedureCodeId )
答案 0 :(得分:0)
注意:代码来自没有编译器的内存,必须进行调整
Service serviceAlias = null;
var subquery = QueryOver.Of<Service>()
.WhereRestrictonOn(s => s.Student.Id).EqProperty(() => serviceAlias.Student.Id)
.WhereRestrictonOn(s => s.Date).EqProperty(() => serviceAlias.Date)
.WhereRestrictonOn(s => s.ProcedureCode.Id).NotEqProperty(() => serviceAlias.ProcedureCode.Id);
var results = session.QueryOver(() => serviceAlias)
.WithSubqueries.WhereExists(subquery)
.List();