为简单明了,假设我有这三个表。
员工 [ ID ]
EmployeeName [ 员工ID, 名称 ]
EmployeeAddress [ 员工ID, 地址 ]
定义的唯一属性/关系位于'子表'EmployeeName& EmployeeAddress
主Employee表中没有属性/关系(集合),例如
我想在EmployeeName和EmployeeAddress之间使用DetachedCriteria执行联接 (不涉及员工),因此
选择EmployeeName.name,EmployeeAddress.address
排序
来自EmployeeName内部联接EmployeeAddress
EmployeeName.employeeId = EmployeeAddress.employeeId和 EmployeeAddress.address,如'%somelocation%',按EmployeeAddress.address
答案 0 :(得分:1)
不完全是你正在寻找的查询,并且没有测试它是否确实有效..但它可能对你有帮助:
var addressCriteria = DetachedCriteria.For<EmployeeAddress>("ea")
.Add(Restrictions.Like("ea.Address", "somelocation", MatchMode.Anywhere));
var nameCriteria = DetachedCriteria.For<EmployeeName>("en")
.Add(Subqueries.PropertyIn("en.Employee", addressCriteria))
.SetProjection(Projections.Property("en.Name"));