This commit is contained in:
shadowik 2023-03-09 07:30:15 +03:00
parent d8c6b81849
commit 8cde12c752
5 changed files with 5 additions and 11 deletions

View File

@ -12,8 +12,8 @@ using PizzeriaDatabaseImplement;
namespace PizzeriaDatabaseImplement.Migrations namespace PizzeriaDatabaseImplement.Migrations
{ {
[DbContext(typeof(PizzeriaDatabase))] [DbContext(typeof(PizzeriaDatabase))]
[Migration("20230309000843_InitialCreate")] [Migration("20230308222141_InitMigration")]
partial class InitialCreate partial class InitMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace PizzeriaDatabaseImplement.Migrations namespace PizzeriaDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialCreate : Migration public partial class InitMigration : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)

View File

@ -63,11 +63,9 @@ namespace PizzeriaDatabaseImplement.Models
{ {
var pizzaComponents = context.PizzaComponents.Where(rec => rec.ProductId == model.Id).ToList(); var pizzaComponents = context.PizzaComponents.Where(rec => rec.ProductId == model.Id).ToList();
if (pizzaComponents != null && pizzaComponents.Count > 0) if (pizzaComponents != null && pizzaComponents.Count > 0) {
{ // удалили те, которых нет в модели
context.PizzaComponents.RemoveRange(pizzaComponents.Where(rec => !model.PizzaComponents.ContainsKey(rec.ComponentId))); context.PizzaComponents.RemoveRange(pizzaComponents.Where(rec => !model.PizzaComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges(); context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateComponent in pizzaComponents) foreach (var updateComponent in pizzaComponents)
{ {
updateComponent.Count = model.PizzaComponents[updateComponent.ComponentId].Item2; updateComponent.Count = model.PizzaComponents[updateComponent.ComponentId].Item2;

View File

@ -10,7 +10,7 @@ namespace PizzeriaDatabaseImplement
{ {
if (!optionsBuilder.IsConfigured) if (!optionsBuilder.IsConfigured)
{ {
optionsBuilder.UseSqlServer(@"Server=shadowik;Initial Catalog=PizzeriaDatabase;Integrated Security=True;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=SHADOWIK\SHADOWIK;Initial Catalog=PizzeriaDatabase;Integrated Security=True;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -20,8 +20,4 @@
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" /> <ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project> </Project>