You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue as per subject. Please see comment in code fragment below.
publicclassTestContext:DbContext{RouteMaster{get;set;}publicasync Task TestAsync(){varbadTestQuery=fromrminRouteMasterlet schedules =fromrsin rm.Schedules
where rs.CutOffTime >= new TimeSpan(9,0,0)&& rs.CutOffTime <= new TimeSpan(17,0,0)selectrsselectnew{// This query will return full entity
rm,
HasActiveSchedule = schedules.Any()};// This will result in N+1 queries. One for RouteMaster and N for the RouteMaster's SchedulesvarbadTestResult=await badTestQuery.ToArrayAsync().ConfigureAwait(false);vargoodTestQuery=fromrminRouteMasterlet schedules =fromrsin rm.Schedules
where rs.CutOffTime >= new TimeSpan(9,0,0)&& rs.CutOffTime <= new TimeSpan(17,0,0)selectrsselectnew{// This query will project all properties of the entity, same as it would be in the above bad query
rm.Id,
rm.RouteNumber,
HasActiveSchedule = schedules.Any()};// This will result in one select statement with the RouteMaster's Schedules as sql subqueryvargoodTestResult=await goodTestQuery.ToArrayAsync().ConfigureAwait(false);}classRouteMasterRecord{publicGuidId{get;privateset;}publicstringRouteNumber{get;privateset;}publicIReadOnlyCollection<RouteScheduleRecord> Schedules {get;privateset;}}classRouteScheduleRecord{publicGuidId{get;privateset;}publicTimeSpanCutOffTime{get;privateset;}}}
Further technical details
EF Core version: 2.1.0-preview1-final
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.5.7
The text was updated successfully, but these errors were encountered:
Issue as per subject. Please see comment in code fragment below.
Further technical details
EF Core version: 2.1.0-preview1-final
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.5.7
The text was updated successfully, but these errors were encountered: