Skip to content

Instantly share code, notes, and snippets.

@Alexei000
Created September 5, 2017 14:26
Show Gist options
  • Save Alexei000/9830c51f0376485180355938a0d8e449 to your computer and use it in GitHub Desktop.
Save Alexei000/9830c51f0376485180355938a0d8e449 to your computer and use it in GitHub Desktop.
Medium article - direct fetch with eager loading
var envIds = new List<int> {5};
DateTime fromDate = DateTime.Now.AddDays(-7).Date;
DateTime toDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
var results = DataAccess.ImportingSystemTestResultRepository.All
.Include(tr => tr.ImportingSystemTestRunTime)
.Include(tr => tr.ImportingSystemTestQueue)
.Include(tr => tr.ImportingSystemTest)
.Include(tr => tr.ImportingSystem)
.Include(tr => tr.Environment)
.Include(tr => tr.AppUser)
.Select(tr => new
{
tr.ImportingSystemTestResultId,
tr.EnteredTimestamp,
tr.RunTimestamp,
tr.ImportingSystemTestId,
tr.EnvironmentId,
tr.ImportingSystemTestExecutionStatusId,
tr.ImportingSystemTestQueue.RequestId,
tr.ImportingSystemTestRunTime.FirstOrDefault().DurationMs,
tr.ImportingSystemTest.TestName,
tr.ImportingSystem.ImportingSystemName,
tr.Environment.Name,
FullName = tr.AppUser.LastName + " " + tr.AppUser.FirstName
})
.Where(x => x.EnteredTimestamp >= fromDate && x.EnteredTimestamp <= toDate)
.Take(500)
.ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment