NHibernate - WHERE EXISTS(X)

时间:2009-02-03 16:56:07

标签: nhibernate

我有以下表格(简化):

Product(Id, Name)
OrderItem(Id, ProductId)

...映射到以下类:

Product {Id, Name}
OrderItem {Id, Product (many-to-one)}

我需要(N)Hibernate语法来检索Orders中出现的产品 SQL将类似于:

select *
from   Product
where  exists (
       select *
       from   OrderItem
       where  OrderItem.ProductId = Product.Id)

如何创建标准?

1 个答案:

答案 0 :(得分:3)

事实证明这很容易......

var query = session.CreateQuery(
            "select distinct oi.Product from OrderItem oi");
return query.List<Product>();