I have the following database structure (EDMX models):
public class Company
{
public Guid Id { get; set; }
public virtual ICollection<Location> Locations { get; set; }
}
public class Location
{
public Guid Id { get; set; }
public virtual Company Company { get; set; }
public Guid CompanyId { get; set; }
public virtual ICollection<ReportA> ReportsA { get; set; }
public virtual ICollection<ReportB> ReportsB { get; set; }
public virtual ICollection<ReportC> ReportsC { get; set; }
}
public class ReportA
{
public virtual Location Location { get; set; }
public Guid LocationId { get; set; }
}
public class ReportB
{
public virtual Location Location { get; set; }
public Guid LocationId { get; set; }
}
public class ReportC
{
public virtual Location Location { get; set; }
public Guid LocationId { get; set; }
}
One company can have many places. At each location there are many reports of the A, B and C.
The columns of the tables ReportA, ReportB, ReportCis different. Each of the tables Reporthas approximately 40,000 rows.
Tables Companyand Locationhave ~ 5000 rows
I need to get all the data and make a final report.
The code:
using (ComapnyEntities dataBaseContext = new ComapnyEntities())
{
IQueryable<Locations> query = dataBaseContext.Locations
.AsNoTracking()
.Where(location => companyIds.Contains(location.CompanyId))
.Include(location => location.Company)
.Include(location => location.ReportsA)
.Include(location => location.ReportsB)
.Include(location => location.ReportsC);
return query.ToList();
}
In most cases, I can use Skip()and methods Take()that speed up execution (i.e. .Take(10)), but in one specific case I need to pull out all the locations along with company information, ReportsA, ReportsB, ReportsC.
Stackoverflow, Include() . qaru.site/questions/380698/...
4 000 * 4 000 * 40 000 * 40 000 * 40 000 = ?? (1.024e+21)
" " , 15 (), .
, ?
- Entity-framework Include() -
- Non-Clustured
Location.CompanyId, ReportA.LocationId, ReportB.LocationId, ReportC.LocationId, LocationId - ( , ) - SQL-, , 10 .
.Inlude() .IncludeOptimized(), .
SQL Server 2014 8.1
? ?