Thanks for replying. I had seen this patch and that is what prompted
me to try the way I did. However, I am using a detached criteria to
build my search query and that's the issue. Looking at the source,
ProjectionCriteria is only present on CriteriaImpl. It is not on
ICriteria or DetachedCriteria.

Is this an oversight or is there a reason that it can't be on
DetachedCriteria? How should I go about getting this to work? It is
essential that I use a detached criteria as I pass the dc to a list of
search filters which apply actions to it. Similar to Ayende's post:

http://ayende.com/Blog/archive/2008/10/16/making-the-complex-trivial-rich-domain-querying.aspx

All these new features aside. How have people done this in the past. I
have found a workaround for the lack of having clause:

http://www.nablasoft.com/Alkampfer/?p=152

but this results in a correlated subquery which would kill
performance. I have googled the life out of this and not turned up any
examples.

On Aug 14, 8:08 am, cws <cw.stenb...@gmail.com> wrote:
> Hello!
>
> Maybe you found this on your own by now but anyway
>
> Look on thishttp://nhjira.koah.net/browse/NH-1280
>
> and in the Nhibernate.Test project on the same corresponding test
>
> On Aug 10, 7:56 pm, imm102 <ianmmc...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I just upgraded to 2.1.0 andProjectionCriteriais now no where to be
> > seen :( Does anyone have any examples of how I can do this relatively
> > common query?
>
> > Thanks,
>
> > On Aug 10, 3:58 pm, imm102 <ianmmc...@gmail.com> wrote:
>
> > > Hi,
>
> > > I am trying to come up with a criteria to restrict an aggregate root
> > > based on a set of tagIds.
>
> > > public class Foo
> > > {
> > >      public virtual int Id { get;set; }
> > >      public virtual IList<Tag> Tags { get;set; }
>
> > > }
>
> > > public class Tag
> > > {
> > >      public virtual int Id { get;set; }
> > >      public virtual string Text { get;set; }
>
> > > }
>
> > > As you can see I have no reference from a tag back to a Foo because
> > > tags can refer to many different entities. The Query I have so far is
> > > below (I am passing a list of tag Ids into the idsIn collection.
>
> > > IList<int> idsIn;
>
> > > var dc = DetachedCriteria.For(typeof(Foo), "f").
> > >                 .CreateCriteria("Tags", "t")
> > >                 .Add(Restrictions.InG("t.Id", idsIn))
> > >             .SetProjection( Projections.ProjectionList()
> > >               .Add(Projections.Property("f.Id"))
> > >               .Add(Projections.RowCount(), "RowCount")
> > >               .Add(Projections.GroupProperty("f.Id")))
> > >           .ProjectionCriteria.Add(Restrictions.Eq("RowCount",
> > > idsIn.Count));
>
> > > }
>
> > > var c = Session.CreateCriteria(typeof(Foo)).Add(Subqueries.PropertyIn
> > > ("Id", dc))
>
> > > I am using a projection to count the number of rows returned. I want
> > > to filter on the number of ids passed so if tags "X", "Y", "Z" are
> > > passed in then it matched only Foos which have all three. I get the
> > > exception {"Could not find property RowCount on Model.Foo"}
>
> > > I don't know if this is the correct/best way to be doing this sort of
> > > query. I have also read thatProjectionCriteriadoesn't work properly
> > > until 2.1.0 which I have yet to upgrate to.
>
> > > Any help would be great.
>
> > > Thanks,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to