NHibernate QueryOver with ManytoMany

杀马特。学长 韩版系。学妹 提交于 2019-11-27 18:45:48

问题


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.

I've written the following:

            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 just has ProductId / CategoryId, and I'm trying to select all the products in a specific category.

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


回答1:


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();

What a mission :)



来源:https://stackoverflow.com/questions/3900779/nhibernate-queryover-with-manytomany

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!