Why can't you just get the most recent 'Bar' and then navigate to the parent
foo in c#?
session.CreateCriteria(typeof(Bar), "bar")
.AddOrder(Order.Desc("bars.Added_On"))
.SetMaxResult(1)
If you need to restrict this to a certain ParentFood
.Add(Restrictions.Eq("bar.ParentFood", foo))
Then you'll get a 'bar' as a result.
Bar b = criteria.List<Bar>()[0];
Foo f = b.Foo;
...
And from now on don't ask using Foo and Bar. Please use something else!
-Will
On Thu, Dec 18, 2008 at 2:23 PM, Shane C <[email protected]> wrote:
>
> I have a class Foo which has a list of Bar instances.
>
> Foo
> Bars : IList<Bar>
>
> And the Bar class which has the following
>
> ParentFood Foo
> Added_On int
>
> I want to select all Foos and return only the most recent Bar
>
> Session.CreateCriteria(typeof(Foo), "foo")
> .CreateCriteria("Bars", "bars")
> .AddOrder(Order.Desc("bars.Added_On"))
> .SetMaxResult(1)
>
> But the MaxResult works against Foo. Obviously I need to create a
> separate criteria but I'm not sure how I would link it back to the Foo
> criteria to get the ParentFoo.
>
> Thoughts?
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---