diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs new file mode 100644 index 0000000..a0ce249 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs @@ -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 Components { set; get; } + public virtual DbSet Furnitures { set; get; } + public virtual DbSet FurnitureComponents { set; get; } + public virtual DbSet Orders { set; get; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj index 45fec34..a46e4e9 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj @@ -20,8 +20,4 @@ - - - - diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs index 9856be4..3e7fa61 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -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),