gpt4 book ai didi

nhibernate - 如何使用 QueryOver api 从限制中定位别名?

转载 作者:行者123 更新时间:2023-12-04 02:08:33 25 4
gpt4 key购买 nike

据我所知,QueryOver api 不允许您通过名称引用别名,而是使用类型化对象。如何向针对别名的查询添加限制?

例如,我想完成类似于以下内容的事情:

var query = session.QueryOver<Person>().JoinQueryOver(x => x.Dogs, () => dogAlias);

return query.Where(Restrictions.Disjunction()
.Add(Restrictions.Like("Name", searchQuery, MatchMode.Anywhere))
.Add(Restrictions.Like("dogAlias.Name", searchQuery, MatchMode.Anywhere)));

最佳答案

代替:

Restrictions.Like("dogAlias.Name", searchQuery, MatchMode.Anywhere)

用:
Restrictions.On(() => dogAlias.Name).IsLike(searchQuery, MatchMode.Anywhere)

因此,完整的查询将变为:
var query = session.QueryOver<Person>()
.JoinQueryOver(x => x.Dogs, () => dogAlias);

return query.Where(Restrictions.Disjunction()
.Add(Restrictions.On<Person>(p => p.Name).IsLike(searchQuery, MatchMode.Anywhere))
.Add(Restrictions.On(() => dogAlias.Name).IsLike(searchQuery, MatchMode.Anywhere)));

关于nhibernate - 如何使用 QueryOver api 从限制中定位别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5204610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com