NHibernate 多重标准困难

发布于 2024-08-23 21:24:05 字数 554 浏览 6 评论 0原文

我在 NHibernate Criteria 搜索中进行多次连接时遇到困难。假设我有一个宠物表,我想返回所有宠物类别为狗、主人性别为女性、按宠物生日排序的宠物。我已经尝试了很多排列来了解如何得到这个,但一直无法弄清楚。我的最新迭代如下:

var recentPets = session.CreateCriteria(typeof(Pet))
            .AddOrder(Order.Desc("PetBirthday"))
            .CreateCriteria("PetType", "pt", JoinType.InnerJoin)
            .CreateCriteria("PetOwnerId", "po", JoinType.InnerJoin)
            .Add(Expression.Eq("pt.PetTypeName", petType))
            .Add(Expression.Eq("po.PersonGender", gender))
            .List<Pet>();

非常感谢您的帮助!

I'm having difficulties with multiple joins in the NHibernate Criteria search. Say I had a pet table, and I wanted to return all pets where the pet category was Dog, and the owner gender was female, ordered by the pet birthday. I've tried a bunch of permutations for how I can get this but haven't been able to figure it out. My latest iteration is as follows:

var recentPets = session.CreateCriteria(typeof(Pet))
            .AddOrder(Order.Desc("PetBirthday"))
            .CreateCriteria("PetType", "pt", JoinType.InnerJoin)
            .CreateCriteria("PetOwnerId", "po", JoinType.InnerJoin)
            .Add(Expression.Eq("pt.PetTypeName", petType))
            .Add(Expression.Eq("po.PersonGender", gender))
            .List<Pet>();

Thanks so much for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2024-08-30 21:24:05

您不使用 Hibernate/Java 持久性查询语言来执行查询是否有原因?

select p from Pet p
join p.owner o
where o.gender = :gender
and p.type.name = :petType
order by p.birthday

Is there a reason you are not using the Hibernate/Java persistence query language to perform the query?

select p from Pet p
join p.owner o
where o.gender = :gender
and p.type.name = :petType
order by p.birthday
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文