Hi, fellow NH users!

Let's say I have two classes, with a simple many-to-one mapping:

class A { }
class B
{
    public virtual A A {get;set;}
    public virtual int Foo {get;set;}
}

I need to get a list of A's for which a B with Foo=n exists.
I tried the following:

var aList = session.CreateCriteria<B>()
                .Add(Restrictions.Eq("Foo", n))
                .SetProjection(Projections.Property("A")
                .List<A>();

But if I do that, I get a list of A proxies.
Using .SetFetchMode("A", FetchMode.Join) doesn't fix it.

My current workaround is:

var aList = session.CreateCriteria<B>()
                .Add(Restrictions.Eq("Foo", n))
                .SetFetchMode("A", FetchMode.Join)
                .List<B>()
                .Select(b => b.A)
                .ToList();

But I'd really like to get rid of it.
Any ideas? (besides switching to HQL, which is problematic because I'm
dynamically adding other restrictions)


   Diego

--

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=.


Reply via email to