下面的代碼片段描述了我想要使用查詢做什麼,但它爆炸與上述錯誤。NHibernate.QueryException:重複的關聯路徑
有建築物和AttributeValues之間的1對多的關係,我的目的是要找到具有的"Large"
一個AttributeValue
和"Blue"
一個AttributeValue
所有建築物。
var attributeValueAlias1 = new AttributeValue();
var attributeValueAlias2 = new AttributeValue();
var result = repository
.CreateCriteriaFor<Buildings>()
.Join(o=>o.AttributeValues,()=> attributeValueAlias1)
.Join(o=>o.AttributeValues,()=> attributeValueAlias2)
.Add(() => attributeValueAlias1.Value == "Large")
.Add(() => attributeValueAlias2.Value == "Blue")
.List();
有幾個帖子在那裏,但沒有一個解決問題的描述here和here。
我可以做這麼一個成員資格測試使用criteria.GetCriteriaByAlias(alias)
增加,因此不會出現重複的別名錯誤,但那麼只有一個連接添加別名之前,它導致SQL where子句,這將永遠是真實的
SELECT *
FROM Buildings this_
inner join AttributeValues attributev1_
on this_.Id = attributev1_.BuildingId
WHERE
attributev1_.Value = 'Large'
and attributev1_.Value = 'Blue'
這不是一個複雜或不尋常的查詢,所以如果沒有解決方法,我會感到驚訝。
只是爲了信息,我已經成功地創建使用HQL等效工作查詢 但不希望有將我們的動態標準,如果可能的話 根據查詢到HQL。 –
類似的問題在這裏:[重複協會](http://stackoverflow.com/questions/3881286/i-am-getting-a-duplicate-association-path-error-in-the-nhibernate-criteria-whe)希望它幫助 - 無法在工作中測試它。 – matt
感謝您的建議 - 他們似乎得出了相同的結論,它不能用Criteria完成,但它似乎令人驚訝,因爲它是這樣一個簡單的查詢。 –