How to eager load sibling data using LINQ to SQL?

前端 未结 2 2135
不知归路
不知归路 2021-02-19 02:38

The goal is to issue the fewest queries to SQL Server using LINQ to SQL without using anonymous types. The return type for the method will need to be IList

相关标签:
2条回答
  • 2021-02-19 02:49

    What you have should be correct, you need to add this dataContext.DeferredLoadingEnabled = false; in addition to the LoadOptions you are already setting.

    0 讨论(0)
  • 2021-02-19 03:08
    var children2 = from child2 in dataContext.Child2
                    where children.Any(c1 => c1.Parent == child2.Parent)
                    select child2;
    

    Should result in a single exists query, so it will end up being two queries.

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