NHibernate QueryOver 与多对多 [英] NHibernate QueryOver with ManytoMany

查看:23
本文介绍了NHibernate QueryOver 与多对多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 QueryOver,但我一生都无法弄清楚如何进行简单的多对多查询.

I'm in the process of learning QueryOver, but I can't for my life figure out how to do simple many to many queries.

我写了以下内容:

            var result = Session.CreateCriteria(typeof (Product))
                .CreateAlias("Categories", "categories")
                .Add(Property.ForName("categories.Id").Eq(categoryId))
                .List<Product>();

这达到了预期的结果.基本上我有

This achieves the desired result. Basically I have

产品 > 产品类别

类别

Product > ProductCategory < Category

ProductCategory 只有 ProductId/CategoryId,我正在尝试选择特定类别中的所有产品.

ProductCategory just has ProductId / CategoryId, and I'm trying to select all the products in a specific category.

我不知道从哪里开始尝试使用 queryover 执行此操作.

I have no idea where to start with trying to do this with queryover.

推荐答案

我在坚持不懈之后最终解决了这个问题.

I ended up resolving this after a lot of perseverance.

            var result = Session.QueryOver<Product>()
                            .Right.JoinQueryOver<Category>(x => x.Categories)
                            .Where(c => c.Id == categoryId)
                            .List();

什么是使命:)

这篇关于NHibernate QueryOver 与多对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆