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屋!
查看全文