Linq for NHibernate and fetch mode of eager loading

▼魔方 西西 提交于 2019-11-28 17:11:31

just use it more then once.

IList<Entity> GetDataFromDatabase()
{
    var query = session.Linq<Entity>();
    query.Expand("Property1");
    query.Expand("Property2");
    return query.ToList();
}

The new Linq provider does it a little differently:

var customers = session.Query<Customer>().Fetch(c => c.Orders).ToList();

More here: http://mikehadlow.blogspot.com/2010/08/nhibernate-linq-eager-fetching.html

As far as I can see, this is not equivalent: SetFetchMode hydrates an objects tree and the Expand method retrieves a cartesian product.

In contiune to @Mike Hadlow answer, fetching next level (grandchildren) you need to do:

var customers = session.Query<Customer>() .FetchMany(c => c.Orders) .ThenFetchMany(o => o.OrderLines).ToList();

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