NHibernate QueryOver 如何加入未声明的关系 [英] NHibernate QueryOver how to join on non declared relationship
本文介绍了NHibernate QueryOver 如何加入未声明的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何执行以下加入以返回有权访问给定公司 ID 的公司的用户.问题是在 UserAccess 和 User 之间使用 User 对象没有明确的关系,他们只是在字符串属性 Username 上加入:
How to do the following join to return Users who have access to a Company given a company id. The problem is there is no explicit relationship using a User object between UserAccess and User they simply join on the string property Username:
User(Username, Name)
UserAccess(Username, Company)
Company(Id)
Session.QueryOver<Company>()
.Where(c => c.Id == companyId)
.JoinQueryOver<UserCompanyAccess>(u => u.UserAccessList)
.JoinQueryOver<User>(u => **Nope no property, just a string**
推荐答案
可以用子查询来完成
var subquery = QueryOver.Of<Company>()
.Where(c => c.Id == companyId)
.JoinQueryOver<UserCompanyAccess>(u => u.UserAccessList)
.Select(uca => uca.UserName);
var users = session.QueryOver<User>()
.WithSubquery.WhereProperty(u => u.Name).In(subquery)
.List();
这篇关于NHibernate QueryOver 如何加入未声明的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文