Implementing “where not exists” with NHibernate QueryOver

后端 未结 2 2004
我在风中等你
我在风中等你 2021-01-15 00:10

Using the new QueryOver API in NHibernate, I need to do something equivalent of:

select c.*
from Category c
where not exists (
    select *
             


        
2条回答
  •  旧时难觅i
    2021-01-15 00:49

    I'm just running in the same problem, and possible solution is:

    Category aliasCategory = null;
    CategoryProduct aliasCategoryProduct = null;
    
    var qcp = QueryOver.Of(() => aliasCategoryProduct)
              .Where(() => aliasCategoryProduct.ProductID == "DogFood")
              .Where(() => aliasCategory.Id == aliasCategoryProduct.CategoryID)
              .DetachedCriteria;
    
    return _session.QueryOver(() => aliasCategory)
                   .Where(Subqueries.NotExists(qcp));
    

    It works on my similar criteria.

提交回复
热议问题