问题
I have the following linq statement:
var query = from p in session.Query<Parent>().FetchMany(x => x.Children)
select p;
I end up with a new Parent object for each Child in Children. So if i had 5 Children, I would get 5 separate, but identical, Parent objects back. Is this the intended behavior? If i use ISession, I get 1 Parent as expected.
回答1:
This is expected, because Stateless Sessions do not track objects; therefore each row results in a new instance.
回答2:
Have you tried to do a Distinct
call on the query?
var results = query.Distinct();
来源:https://stackoverflow.com/questions/10921959/nhibernate-istatelesssession-and-fetchmany-returning-multiple-parent-records