Does this help
http://devlicio.us/blogs/tuna_toksoz/archive/2009/07/10/querying-on-child-count-with-nhibernate.aspx

Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike




On Sat, Aug 1, 2009 at 2:09 PM, Ricardo Peres <[email protected]> wrote:

>
> Hello,
>
> I have this simple class:
>
> public class SomeClass
> {
>    public Int32 Id { get; set; }
>    public SomeClass Parent { get; set; }
>    public ISet<SomeClass> Children { get; set; }
> }
>
> As you can see, it maps a simple table which is related with itself,
> recursively. All mappings are fine.
> Now, I want to list all records that have children; with HQL, it is
> pretty easy:
>
> var l1 = session.CreateQuery("from SomeClass sc where sc.Children.size
> > 0").List<SomeClass>();
>
> How would I do this with the Criteria API? And what about LINQ to
> NHibernate? The following both fail:
>
> var l2 = session.CreateCriteria<SomeClass>("p").Add
> (NHibernate.Criterion.Expression.Gt("p.Children.Count",
> "0")).List<SomeClass>();
>
> var l3 = (from l in session.Linq<SomeClass>() where l.Children.Count >
> 0 select l).ToList();
>
> var l4 = session.Linq<SomeClass>().Where(l => l.Children.Count >
> 0).ToList();
>
> Can you help?
>
> Thanks,
>
> Ricardo Peres
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to