Исправление модели изделия, создание класса с таблицами
This commit is contained in:
parent
ac8a0e4602
commit
9cc2836618
@ -0,0 +1,26 @@
|
||||
using FurnitureAssemblyDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement
|
||||
{
|
||||
public class FurnitureAssemblyDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=zhu\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Furniture> Furnitures { set; get; }
|
||||
public virtual DbSet<FurnitureComponent> FurnitureComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
}
|
||||
}
|
@ -20,8 +20,4 @@
|
||||
<ProjectReference Include="..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -69,7 +69,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
var furnitureComponents = context.FurnitureComponents.Where(rec => rec.ProductId == model.Id).ToList();
|
||||
if (furnitureComponents != null && furnitureComponents.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ProductComponents.RemoveRange(furnitureComponents.Where(rec
|
||||
context.FurnitureComponents.RemoveRange(furnitureComponents.Where(rec
|
||||
=> !model.FurnitureComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
@ -83,7 +83,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
var furniture = context.Furnitures.First(x => x.Id == Id);
|
||||
foreach (var pc in model.FurnitureComponents)
|
||||
{
|
||||
context.ProductComponents.Add(new FurnitureComponent
|
||||
context.FurnitureComponents.Add(new FurnitureComponent
|
||||
{
|
||||
Furniture = furniture,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
|
Loading…
Reference in New Issue
Block a user