nHibernate - IStatelessSession and FetchMany returning multiple parent records

巧了我就是萌 提交于 2019-12-12 20:23:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!