Hi,

I have a domain with many-to-many relationships such as:

class Product
{
    string Name { get; set; }
    ISet<Seller> Sellers { get; set; }
}

class Seller
{
    string Name { get; set; }
    ISet<Product> Products { get; set; }
}

I want to retrieve all products that match some criteria. I need the
sellers in each product too, so I thought I'd look into setting the
fetch mode. However, I'm running into all sorts of issues doing so and
am wondering whether I'm barking up the wrong tree.

Here are some of the issues I'm having:

1. I cannot combine the use of SetFetchMode with SetAlias, which I
need elsewhere. Doing so causes the fetch mode to be seemingly
ignored. For example:

var query = session.CreateCriteria<Product>()
    .SetFetchMode("Sellers", FetchMode.Eager)
    //.CreateAlias("Sellers", "seller")
    //.Add(Expression.Eq("seller.Name", "Acme"));

If I run as is, only one query is generated. If I uncomment the two
lines, multiple queries are generated when I iterate over the results.

2. I managed to "get around" the above issue by explicitly setting the
join mode on the alias to LeftOuterJoin. However, this gives me
repeated products - one for each of its sellers - rather than one
product with multiple sellers.

Can anyone tell me whether I'm on the right path or not? Should I be
looking into something else - perhaps multiqueries - instead?

Thanks,
Kent

--

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