Use lazy loading of related tables.

This commit is contained in:
2018-08-06 23:33:39 +01:00
parent d540e281cf
commit 7565a8966a
29 changed files with 3077 additions and 681 deletions

View File

@@ -33,7 +33,6 @@ using Cicm.Database;
using Cicm.Database.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace cicm_web.Controllers
{
@@ -73,19 +72,18 @@ namespace cicm_web.Controllers
ViewBag.Letter = id;
return View(id == '\0'
? _context.Machines.Include(c => c.Company).Where(m => m.Type == MachineType.Console)
.ToArray()
: _context.Machines.Include(c => c.Company)
.Where(m => m.Type == MachineType.Console && m.Name.StartsWith(id)).ToArray());
? _context.Machines.Where(m => m.Type == MachineType.Console).ToArray()
: _context.Machines.Where(m => m.Type == MachineType.Console && m.Name.StartsWith(id))
.ToArray());
}
public IActionResult ByYear(int id)
{
ViewBag.Year = id;
return View(_context.Machines.Include(c => c.Company)
.Where(t => t.Type == MachineType.Console && t.Introduced.HasValue &&
t.Introduced.Value.Year == id).ToArray());
return View(_context.Machines.Where(t => t.Type == MachineType.Console &&
t.Introduced.HasValue &&
t.Introduced.Value.Year == id).ToArray());
}
}
}