Thanks for the reply.
Good suggestion but even after making the suggested change to the
joins the query still generates the "NHibernate.QueryException :
duplicate association path: AttributeValues" exception.
Just for info I have managed to create an equivalent working query
using HQL but would prefer not to have to move our dynamic criteria
based querying over to HQL if possible.
Cheers
Neil
On Nov 2, 5:23 pm, John Davidson <
jwdavid...@gmail.com> wrote:
> What is the sql when you try
>
> var result = repository
> .CreateCriteriaFor<Buildings>()
> .Join(o1=>o1.AttributeValues, ()=> attributeValueAlias1)
> .Join(o2=>o2.AttributeValues, ()=> attributeValueAlias2)
> .Add(() => attributeValueAlias1.Value == "Large")
> .Add(() => attributeValueAlias2.Value == "Blue")
> .List();
>
> John Davidson
>
> On Wed, Nov 2, 2011 at 10:33 AM, Neil McLaughlin <
>
>
>
>
>
>
>
>
n...@echelon-solutions.co.uk> wrote:
> > The code fragment below describes what I want to do using criteria but it
> > blows up with the above error.
>
> > There is a 1 to many relationship between Buildings and AttributeValues
> > and my aim is to find all Buildings which have an AttributeValue of "Large"
> > *and* an AttributeValue of "Blue".
>
> > 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();
>
> > There are few posts on this forum and on other sites but none with a
> > solution to the problem which is described here<
http://stackoverflow.com/questions/5940922/duplicate-association-path...> and
> > here<
http://blog.dezfowler.com/2008/06/duplicate-association-path-bug-in.html>
>
> > I can make it so a test is added to see if the alias exists using
> > _criteria.GetCriteriaByAlias(alias) before adding it so the Duplicate alias
> > error does not occur but then there is only a single join and it results in
> > a SQL Where clause which will never be true
>
> > SELECT *
> > FROM Buildings this_
> > inner join AttributeValues attributev1_
> > on this_.Id = attributev1_.BuildingId
> > WHERE
> > attributev1_.Value = 'Large'
> > and attributev1_.Value = 'Blue'
>
> > It is not a complicated or unusual query so I'd be surprised if there
> > isn't a work around.
>
> > We are using NHibernate 2.1
>
> > Thanks in advance
>
> > Neil
>
> > Note: this question has also been posted to StackOverflow here<
http://stackoverflow.com/questions/7981027/nhibernate-queryexception-...>