Linq for NHibernate and fetch mode of eager loading

前端 未结 4 1122
广开言路
广开言路 2020-12-13 03:37

Is there a way to set the fetchmode to eager for more than one object using linq for nhibernate. There seems to be an expand method which only allows me to set one object. H

相关标签:
4条回答
  • 2020-12-13 04:15

    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();

    0 讨论(0)
  • 2020-12-13 04:20

    just use it more then once.

    IList<Entity> GetDataFromDatabase()
    {
        var query = session.Linq<Entity>();
        query.Expand("Property1");
        query.Expand("Property2");
        return query.ToList();
    }
    
    0 讨论(0)
  • 2020-12-13 04:29

    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

    0 讨论(0)
  • 2020-12-13 04:34

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

    0 讨论(0)
提交回复
热议问题