【发布时间】:2011-04-13 09:17:40
【问题描述】:
在 NHibernate 中使用新的 QueryOver API,我需要做一些相当于:
select c.*
from Category c
where not exists (
select *
from CategoryProduct cp
where cp.CategoryID = c.Id
and cp.ProductID = 'DogFood'
)
换句话说:“给我所有不包含狗食的类别”。
我最初的想法是这样的:
IEnumerable<Category> FindCategoriesWithoutProduct(Product product)
{
return _session
.QueryOver<Category>()
.Where(c => c.Products.Contains(product))
.List();
}
但是,这会使NHibernate.Impl.ExpressionProcessor 在System.Collections.Generic.ICollection<T>.Contains() 上出现“无法识别的方法调用”。
我认为一定有其他方法可以做到这一点,可能涉及ICriterion,但我在这里和谷歌上的搜索没有返回任何有用的结果。
【问题讨论】:
标签: nhibernate queryover