But I get the same error if I use CreateAlias aswell. I'm wondering if it's the way DetachedCriteria internally store aliases that makes a duplicate key violation?
Ken Egozi wrote: > CreateCriteria creates a subcriteria and returns it > CreateAlias creates a subcritera, but returns the original (parent) > criteria > so, CreateAlias(..).Add(..) should work for you > > On Thu, Nov 6, 2008 at 1:18 PM, Jimmy Shimizu <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> wrote: > > > Isn't it possible to create a DetachedCriteria that joins table > multiple > times? I have tried doing this (What's the difference between > CreateCriteria and CreateAlias anyway?): > > var alias = "p" + i++; > criteria.CreateCriteria("Property", alias) > .Add(Expression.Eq(alias, p.Value)); > } > > where alias is changeable and p is based on an enumeration. > > > However, I get this: > System.ArgumentException: An item with the same key has already > been added. > at System.ThrowHelper.ThrowArgumentException(ExceptionResource > resource) > at > System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue > value, Boolean add) > at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) > at NHibernate.Util.LinkedHashMap`2.Add(TKey key, TValue value) > at > > NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateAssociationPathCriteriaMap() > > What I want to do is to select items based on if it has 1 or many > subitems in a collection. With a regular SQL statement I would > just join > in subitems for each subitem I want it to have, like this: > > select * from items > INNER JOIN subitems s1 ON s1.item_id = items.item_id AND s1.type = > 'foo' > INNER JOIN subitems s2 ON s2.item_id = items.item_id AND s2.type = > 'bar' > INNER JOIN subitems s3 ON s3.item_id = items.item_id AND s3.type = > 'foobar' > > > How would I replicate this behaviour using NHibernate/ActiveRecord? Or > is HQL the way to go? > > > > > > > -- > Ken Egozi. > http://www.kenegozi.com/blog > http://www.musicglue.com > http://www.castleproject.org > http://www.gotfriends.co.il > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
