NHibernate QueryOver与ManytoMany [英] NHibernate QueryOver with ManytoMany

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

问题描述

我正在学习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

产品> ProductCategory<类别

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与ManytoMany的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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