Kent Boogaart
unread,Nov 25, 2009, 9:47:36 AM11/25/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhusers
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