請考慮以下對象結構。具有2個條件的Nhibernate Queryover子查詢和預查詢者
Product
id : int
name : string
attribute : list of Attribute
Attribute
id : int
name: string
value : string
product_id : int
的問題是: 使用QueryOver如何形成一個子查詢返回所有產品 具備以下條件:
選擇,其中有在同一時間屬性時,所有的產品:
屬性名稱=「顏色」值=「紅色」 和 屬性名稱=「大小」值=「XXL」?
編輯: SQL示例:
select * from Product p where
exists (select id from attribute where name = 'Color' and value = 'Red' and product_id = p.id)
and
exists (select id from attribute where name = 'Size' and value = 'XXL' and product_id = p.id)
你會如何在sql中寫這個查詢?除非你不熟悉sql,否則我通常會這樣做。 –
它需要爲每個屬性有一個子查詢。表現不好。 – Roland
@Roland:是的,你可以寫你想要的SQL嗎?這會讓問題更容易回答。 –