Linq2SQl eager load with multiple DataLoadOptions

后端 未结 3 813
无人共我
无人共我 2020-12-15 09:19

I like to fetch the data with eager-loading using Linq2SQL. The code is similar as :

       DataLoadOptions options = new DataLoadOptions();

       options.         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 09:56

    According to the docs:

    When you query for an object, you actually retrieve only the object you requested. The related objects are not automatically fetched at the same time.

    The DataLoadOptions class provides two methods to achieve immediate loading of specified related data. The LoadWith method allows for immediate loading of data related to the main target. The AssociateWith method allows for filtering related objects.

    Having multiple sql statements doesn't surprise me. I think the difference here is all statements are just loaded up front instead of lazy loading them on demand.

提交回复
热议问题