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

@@ -3,6 +3,7 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.1.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.1" />
</ItemGroup>
<ItemGroup>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Cicm.Database.Migrations
{
public partial class LogosGuid : Migration
{
protected override void Up(MigrationBuilder migrationBuilder) { }
protected override void Down(MigrationBuilder migrationBuilder) { }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -31,15 +31,15 @@ namespace Cicm.Database.Models
public short? CountryId { get; set; }
public CompanyStatus Status { get; set; }
public Iso31661Numeric Country { get; set; }
public Company SoldTo { get; set; }
public CompanyDescription Description { get; set; }
public ICollection<CompanyLogo> CompanyLogos { get; set; }
public ICollection<Gpu> Gpus { get; set; }
public ICollection<Company> InverseSoldToNavigation { get; set; }
public ICollection<MachineFamily> MachineFamilies { get; set; }
public ICollection<Machine> Machines { get; set; }
public ICollection<Processor> Processors { get; set; }
public ICollection<SoundSynth> SoundSynths { get; set; }
public virtual Iso31661Numeric Country { get; set; }
public virtual Company SoldTo { get; set; }
public virtual CompanyDescription Description { get; set; }
public virtual ICollection<CompanyLogo> CompanyLogos { get; set; }
public virtual ICollection<Gpu> Gpus { get; set; }
public virtual ICollection<Company> InverseSoldToNavigation { get; set; }
public virtual ICollection<MachineFamily> MachineFamilies { get; set; }
public virtual ICollection<Machine> Machines { get; set; }
public virtual ICollection<Processor> Processors { get; set; }
public virtual ICollection<SoundSynth> SoundSynths { get; set; }
}
}

View File

@@ -6,6 +6,6 @@
public int CompanyId { get; set; }
public string Text { get; set; }
public Company Company { get; set; }
public virtual Company Company { get; set; }
}
}

View File

@@ -1,12 +1,14 @@
namespace Cicm.Database.Models
using System;
namespace Cicm.Database.Models
{
public class CompanyLogo
{
public int Id { get; set; }
public int CompanyId { get; set; }
public int? Year { get; set; }
public string Guid { get; set; }
public Guid Guid { get; set; }
public Company Company { get; set; }
public virtual Company Company { get; set; }
}
}

View File

@@ -22,8 +22,8 @@ namespace Cicm.Database.Models
public float? DieSize { get; set; }
public long? Transistors { get; set; }
public Company Company { get; set; }
public ICollection<GpusByMachine> GpusByMachine { get; set; }
public ICollection<ResolutionsByGpu> ResolutionsByGpu { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<GpusByMachine> GpusByMachine { get; set; }
public virtual ICollection<ResolutionsByGpu> ResolutionsByGpu { get; set; }
}
}

View File

@@ -6,7 +6,7 @@
public int MachineId { get; set; }
public long Id { get; set; }
public Gpu Gpu { get; set; }
public Machine Machine { get; set; }
public virtual Gpu Gpu { get; set; }
public virtual Machine Machine { get; set; }
}
}

View File

@@ -12,6 +12,6 @@ namespace Cicm.Database.Models
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Processor> Processors { get; set; }
public virtual ICollection<Processor> Processors { get; set; }
}
}

View File

@@ -12,6 +12,10 @@ namespace Cicm.Database.Models
public int Id { get; set; }
public string Extension { get; set; }
public ICollection<InstructionSetExtensionsByProcessor> InstructionSetExtensionsByProcessor { get; set; }
public virtual ICollection<InstructionSetExtensionsByProcessor> InstructionSetExtensionsByProcessor
{
get;
set;
}
}
}

View File

@@ -6,7 +6,7 @@
public int ProcessorId { get; set; }
public int ExtensionId { get; set; }
public InstructionSetExtension Extension { get; set; }
public Processor Processor { get; set; }
public virtual InstructionSetExtension Extension { get; set; }
public virtual Processor Processor { get; set; }
}
}

View File

@@ -12,6 +12,6 @@ namespace Cicm.Database.Models
public short Id { get; set; }
public string Name { get; set; }
public ICollection<Company> Companies { get; set; }
public virtual ICollection<Company> Companies { get; set; }
}
}

View File

@@ -22,12 +22,12 @@ namespace Cicm.Database.Models
public int? FamilyId { get; set; }
public string Model { get; set; }
public Company Company { get; set; }
public MachineFamily Family { get; set; }
public ICollection<GpusByMachine> Gpus { get; set; }
public ICollection<MemoryByMachine> Memory { get; set; }
public ICollection<ProcessorsByMachine> Processors { get; set; }
public ICollection<SoundByMachine> Sound { get; set; }
public ICollection<StorageByMachine> Storage { get; set; }
public virtual Company Company { get; set; }
public virtual MachineFamily Family { get; set; }
public virtual ICollection<GpusByMachine> Gpus { get; set; }
public virtual ICollection<MemoryByMachine> Memory { get; set; }
public virtual ICollection<ProcessorsByMachine> Processors { get; set; }
public virtual ICollection<SoundByMachine> Sound { get; set; }
public virtual ICollection<StorageByMachine> Storage { get; set; }
}
}

View File

@@ -13,7 +13,7 @@ namespace Cicm.Database.Models
public int CompanyId { get; set; }
public string Name { get; set; }
public Company Company { get; set; }
public ICollection<Machine> Machines { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<Machine> Machines { get; set; }
}
}

View File

@@ -9,6 +9,6 @@
public double? Speed { get; set; }
public long Id { get; set; }
public Machine Machine { get; set; }
public virtual Machine Machine { get; set; }
}
}

View File

@@ -38,9 +38,9 @@ namespace Cicm.Database.Models
public float? L2 { get; set; }
public float? L3 { get; set; }
public Company Company { get; set; }
public InstructionSet InstructionSet { get; set; }
public ICollection<InstructionSetExtensionsByProcessor> InstructionSetExtensions { get; set; }
public ICollection<ProcessorsByMachine> ProcessorsByMachine { get; set; }
public virtual Company Company { get; set; }
public virtual InstructionSet InstructionSet { get; set; }
public virtual ICollection<InstructionSetExtensionsByProcessor> InstructionSetExtensions { get; set; }
public virtual ICollection<ProcessorsByMachine> ProcessorsByMachine { get; set; }
}
}

View File

@@ -7,7 +7,7 @@
public float? Speed { get; set; }
public long Id { get; set; }
public Machine Machine { get; set; }
public Processor Processor { get; set; }
public virtual Machine Machine { get; set; }
public virtual Processor Processor { get; set; }
}
}

View File

@@ -16,6 +16,6 @@ namespace Cicm.Database.Models
public long? Palette { get; set; }
public sbyte Chars { get; set; }
public ICollection<ResolutionsByGpu> ResolutionsByGpu { get; set; }
public virtual ICollection<ResolutionsByGpu> ResolutionsByGpu { get; set; }
}
}

View File

@@ -6,7 +6,7 @@
public int ResolutionId { get; set; }
public long Id { get; set; }
public Gpu Gpu { get; set; }
public Resolution Resolution { get; set; }
public virtual Gpu Gpu { get; set; }
public virtual Resolution Resolution { get; set; }
}
}

View File

@@ -6,7 +6,7 @@
public int MachineId { get; set; }
public long Id { get; set; }
public Machine Machine { get; set; }
public SoundSynth SoundSynth { get; set; }
public virtual Machine Machine { get; set; }
public virtual SoundSynth SoundSynth { get; set; }
}
}

View File

@@ -22,7 +22,7 @@ namespace Cicm.Database.Models
public int? WhiteNoise { get; set; }
public int? Type { get; set; }
public Company Company { get; set; }
public ICollection<SoundByMachine> SoundByMachine { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<SoundByMachine> SoundByMachine { get; set; }
}
}

View File

@@ -8,6 +8,6 @@
public long? Capacity { get; set; }
public long Id { get; set; }
public Machine Machine { get; set; }
public virtual Machine Machine { get; set; }
}
}

View File

@@ -43,6 +43,7 @@ namespace Cicm.Database.Models
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
optionsBuilder.UseMySql("server=localhost;port=3306;user=cicm;password=cicmpass;database=cicm");
optionsBuilder.UseLazyLoadingProxies();
}
}

View File

@@ -65,8 +65,7 @@ namespace cicm_web.Controllers
public IActionResult View(int id)
{
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
Company company = _context.Companies.Where(c => c.Id == id).Include(c => c.Description)
.Include(c => c.Machines).Include(c => c.Country).FirstOrDefault();
Company company = _context.Companies.FirstOrDefault(c => c.Id == id);
if(company == null) return Index();

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,18 +72,17 @@ namespace cicm_web.Controllers
ViewBag.Letter = id;
return View(id == '\0'
? _context.Machines.Include(c => c.Company).Where(m => m.Type == MachineType.Computer)
.ToArray()
: _context.Machines.Include(c => c.Company)
.Where(m => m.Type == MachineType.Computer && m.Name.StartsWith(id)).ToArray());
? _context.Machines.Where(m => m.Type == MachineType.Computer).ToArray()
: _context.Machines.Where(m => m.Type == MachineType.Computer && 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.Computer && t.Introduced.HasValue &&
return View(_context.Machines.Where(t => t.Type == MachineType.Computer &&
t.Introduced.HasValue &&
t.Introduced.Value.Year == id).ToArray());
}
}

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,18 +72,17 @@ 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 &&
return View(_context.Machines.Where(t => t.Type == MachineType.Console &&
t.Introduced.HasValue &&
t.Introduced.Value.Year == id).ToArray());
}
}

View File

@@ -53,8 +53,8 @@ namespace cicm_web
services.AddMvc();
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
services.AddDbContext<cicmContext>(options =>
options
services.AddDbContext<cicmContext>(options => options
.UseLazyLoadingProxies()
.UseMySql("server=localhost;port=3306;user=cicm;password=cicmpass;database=cicm"));
}

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.0.99.292</Version>
<Version>3.0.99.301</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>
@@ -16,6 +16,7 @@
<ItemGroup>
<PackageReference Include="Markdig" Version="0.15.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.1.1" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.0.6" />
<PackageReference Include="MSBump" Version="2.3.2" PrivateAssets="All" />
<PackageReference Include="MySql.Data" Version="6.10.6" />