使用 QueryOver 进行子查询
我在使用子查询和 queryover 时遇到问题。
这就是我所拥有的
var address = QueryOver.Of<Address>()
.Where(x => x.City.IsLike("%" + city + "%")).Select(x => x.Person.Id);
var result = Session.QueryOver<Person>()
.Where(x => x.Type.IsLike(type + "%"))
.And(x => x.Name.IsLike("%" + name + "%"))
.WithSubquery.WhereExists(address);
,我有一个人的表,一个人有多个地址。
所以 人 id、名称、类型
和地址将有 PersonId 和城市等。
所以想按姓名和类型以及地址表中的城市搜索人员
I have a issue in using subquery with queryover.
This is what I have
var address = QueryOver.Of<Address>()
.Where(x => x.City.IsLike("%" + city + "%")).Select(x => x.Person.Id);
var result = Session.QueryOver<Person>()
.Where(x => x.Type.IsLike(type + "%"))
.And(x => x.Name.IsLike("%" + name + "%"))
.WithSubquery.WhereExists(address);
I have a table for Person and a person has multiple addreses.
So
Person
id, name, type
and Address will have
PersonId and city etc.
So want to search a person by name and type as well as City which is in Address table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的操作:
您需要使用 QueryOver 的别名版本。这样您就可以从其他查询中引用 Person 元素,这些查询最终将链接到您的主查询中。
这与执行以下操作相同
Try something like this:
You need to use QueryOver's version of aliasing. This way you can reference the Person element from other queries which you will eventually link into your main query.
This is the same as doing something like the following