diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index d451de5..41fcc45 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; @@ -49,18 +50,9 @@ namespace SushiBarDatabaseImplement.Implements { using var context = new SushiBarDatabase(); return context.Orders - .Select(x => new OrderViewModel - { - Id = x.Id, - SushiId = x.SushiId, - Count = x.Count, - Sum = x.Sum, - Status = x.Status, - DateCreate = x.DateCreate, - DateImplement = x.DateImplement, - SushiName = x.Sushi.SushiName - }) - .ToList(); + .Include(x => x.Sushi) + .Select(x => x.GetViewModel) + .ToList(); } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index aac6f84..5e3bac7 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -20,7 +20,7 @@ namespace SushiBarDatabaseImplement.Models public DateTime DateCreate { get; set; } public DateTime? DateImplement { get; set; } public int Id { get; set; } - public virtual Sushi Sushi { get; set; } + public Sushi Sushi { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -59,6 +59,7 @@ namespace SushiBarDatabaseImplement.Models DateImplement = DateImplement, Id = Id, Status = Status, + SushiName = Sushi.SushiName, }; } } diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 58f8313..84da6c9 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -9,7 +9,7 @@ namespace SushiBarDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-JC256C6\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); }