Tag: select n plus 1

EF Core嵌套Linq在N + 1个SQL查询中选择结果

我有一个数据模型,其中’Top’对象有0到N’Sub’对象。 在SQL中,这是通过外键dbo.Sub.TopId 。 var query = context.Top //.Include(t => t.Sub) Doesn’t seem to do anything .Select(t => new { prop1 = t.C1, prop2 = t.Sub.Select(s => new { prop21 = s.C3 //C3 is a column in the table ‘Sub’ }) //.ToArray() results in N + 1 queries }); var res = query.ToArray(); 在Entity Framework 6(延迟加载关闭)中,此Linq查询将转换为单个 […]