在这里,我获得了一个代表可以访问的代理商列表。
var agencies = _session.QueryOver<AgencyRep>()
.JoinQueryOver<AgencyRepsSecondaryAgency>(r => r.AgencyRepsSecondaryAgencies)
.Where(a => a.AgencyRepId == user.Id)
.List();
在我获得我的代理商列表之后,我想要进行SQL搜索,其值是在agencies.id列中。
var data = _session.QueryOver<Staging.Case>()
.Where(x => x.AgencyId ???? agencies)
.List();
不确定如何用流利的nhibernate实现这样的东西。任何帮助将不胜感激。
答案 0 :(得分:5)
试试这个:
var data = _session.QueryOver<Staging.Case>()
.WhereRestrictionOn(x => x.AgencyId).IsIn(agencies.Select(a => a.Id).ToArray())
.List();
编辑:如果您之后不需要代理商 - 您可以通过以下方式进行优化:
var agencyIds = _session.QueryOver<AgencyRep>()
.JoinQueryOver<AgencyRepsSecondaryAgency>(r => r.AgencyRepsSecondaryAgencies)
.Where(a => a.AgencyRepId == user.Id)
.Select(a => a.Id)
.List<long>(); //if your .Id is of type long - replace with the correct type
var data = _session.QueryOver<Staging.Case>()
.WhereRestrictionOn(x => x.AgencyId).IsIn(agencyIds.ToArray())
.List();
保存通过连接发送的一些数据
答案 1 :(得分:1)
这应该可行,未经测试但您可以尝试:
var subquery = QueryOver.Of<AgencyRep>()
.JoinQueryOver<AgencyRepsSecondaryAgency>(r => r.AgencyRepsSecondaryAgencies)
.Where(a => a.AgencyRepId == user.Id)
var data = _session.QueryOver<Staging.Case>()
.WithSubquery.WhereProperty(x => x.AgencyId).In(subquery)
.List();