nhibernate - Join two tables by comparing equal value on two columns -
for simplicity , clarity, assume have these 3 tables.
employee [ id ]
employeename [ employeeid, name ]
employeeaddress [ employeeid, address ]
the properties/relationships defined in 'sub-tables' employeename & employeeaddress
- employeename belongsto employee
- employeeaddress belongsto employee
there are no properties/relationships (collections) in main employee table such as
- employee hasmany employeename
- employee hasmany employeeadress.
i want perform join using detachedcriteria between employeename , employeeaddress only (not involving employee), such
select employeename.name, employeeaddress.address
employeename inner join employeeaddress
employeename.employeeid = employeeaddress.employeeid , employeeaddress.address '%somelocation%' order employeeaddress.address
not query you're looking , haven't tested if works.. may you:
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"));
Comments
Post a Comment