diff --git a/2_Libs/EFCore/BooksLib/BooksLib.csproj b/2_Libs/EFCore/BooksLib/BooksLib.csproj index 017acd43..bda2bcd8 100644 --- a/2_Libs/EFCore/BooksLib/BooksLib.csproj +++ b/2_Libs/EFCore/BooksLib/BooksLib.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -7,8 +7,8 @@ - - + + diff --git a/2_Libs/EFCore/ConflictHandling-FirstWins/ConflictHandling-FirstWins.csproj b/2_Libs/EFCore/ConflictHandling-FirstWins/ConflictHandling-FirstWins.csproj index 51855e26..f91469db 100644 --- a/2_Libs/EFCore/ConflictHandling-FirstWins/ConflictHandling-FirstWins.csproj +++ b/2_Libs/EFCore/ConflictHandling-FirstWins/ConflictHandling-FirstWins.csproj @@ -12,13 +12,13 @@ --> - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/2_Libs/EFCore/ConflictHandling-LastWins/ConflictHandling-LastWins.csproj b/2_Libs/EFCore/ConflictHandling-LastWins/ConflictHandling-LastWins.csproj index 51855e26..f91469db 100644 --- a/2_Libs/EFCore/ConflictHandling-LastWins/ConflictHandling-LastWins.csproj +++ b/2_Libs/EFCore/ConflictHandling-LastWins/ConflictHandling-LastWins.csproj @@ -12,13 +12,13 @@ --> - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/2_Libs/EFCore/Cosmos/Cosmos.csproj b/2_Libs/EFCore/Cosmos/Cosmos.csproj index 62c117b4..5c49fc66 100644 --- a/2_Libs/EFCore/Cosmos/Cosmos.csproj +++ b/2_Libs/EFCore/Cosmos/Cosmos.csproj @@ -9,14 +9,14 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/2_Libs/EFCore/Cosmos/MenusContext.cs b/2_Libs/EFCore/Cosmos/MenusContext.cs index b9e3776e..caca8baa 100644 --- a/2_Libs/EFCore/Cosmos/MenusContext.cs +++ b/2_Libs/EFCore/Cosmos/MenusContext.cs @@ -1,15 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -internal class MenusContext : DbContext +internal class MenusContext(DbContextOptions options, IOptions restaurantOptions) : DbContext(options) { - private readonly string _restaurantId; - - public MenusContext(DbContextOptions options, IOptions restaurantOptions) - : base(options) - { - _restaurantId = restaurantOptions.Value.RestaurantId ?? throw new System.Exception("restaurantid required"); - } + private readonly string _restaurantId = restaurantOptions.Value.RestaurantId ?? throw new System.Exception("restaurantid required"); public DbSet MenuCards => Set(); diff --git a/2_Libs/EFCore/Cosmos/Program.cs b/2_Libs/EFCore/Cosmos/Program.cs index 378dd2ed..8efcb764 100644 --- a/2_Libs/EFCore/Cosmos/Program.cs +++ b/2_Libs/EFCore/Cosmos/Program.cs @@ -23,6 +23,6 @@ await runner.CreateDatabaseAsync(); await runner.AddMenuCardAsync(); -await runner.AddAddtionalCardsAsync(); +await runner.AddAdditionalCardsAsync(); await runner.ShowCardsAsync(); await runner.DeleteDatabaseAsync(); diff --git a/2_Libs/EFCore/Cosmos/Runner.cs b/2_Libs/EFCore/Cosmos/Runner.cs index 33d3da3a..dc829089 100644 --- a/2_Libs/EFCore/Cosmos/Runner.cs +++ b/2_Libs/EFCore/Cosmos/Runner.cs @@ -6,20 +6,13 @@ internal class RestaurantConfiguration public string? RestaurantId { get; set; } } -internal class Runner +internal class Runner(MenusContext menusContext, IOptions options) { - private readonly string _restaurantId; - private readonly MenusContext _menusContext; - - public Runner(MenusContext menusContext, IOptions options) - { - _menusContext = menusContext; - _restaurantId = options.Value.RestaurantId ?? throw new ArgumentException("restaurant-id required"); - } + private readonly string _restaurantId = options.Value.RestaurantId ?? throw new ArgumentException("restaurant-id required"); public async Task CreateDatabaseAsync() { - await _menusContext.Database.EnsureCreatedAsync(); + await menusContext.Database.EnsureCreatedAsync(); } public async Task AddMenuCardAsync() @@ -27,8 +20,8 @@ public async Task AddMenuCardAsync() Console.WriteLine(nameof(AddMenuCardAsync)); MenuCard soupCard = new("Soups", _restaurantId); - MenuItem[] soups = new MenuItem[] - { + MenuItem[] soups = + [ new("Consommé Célestine (with shredded pancake)") { Price = 4.8m @@ -41,33 +34,33 @@ public async Task AddMenuCardAsync() { Price = 4.8m } - }; + ]; foreach (var soup in soups) { soupCard.MenuItems.Add(soup); } - _menusContext.MenuCards.Add(soupCard); + menusContext.MenuCards.Add(soupCard); - int records = await _menusContext.SaveChangesAsync(); + int records = await menusContext.SaveChangesAsync(); Console.WriteLine($"{records} added"); Console.WriteLine(); } - public async Task AddAddtionalCardsAsync() + public async Task AddAdditionalCardsAsync() { Random random = new(); var menus = Enumerable.Range(1, 10).Select(i => new MenuItem($"menu {i}") { Price = random.Next(8) }).ToList(); var cards = Enumerable.Range(1, 5).Select(i => new MenuCard($"card {i}", _restaurantId) { MenuItems = menus }); - await _menusContext.MenuCards.AddRangeAsync(cards); - await _menusContext.SaveChangesAsync(); + await menusContext.MenuCards.AddRangeAsync(cards); + await menusContext.SaveChangesAsync(); } public async Task ShowCardsAsync() { - var cards = await _menusContext.MenuCards + var cards = await menusContext.MenuCards .Where(c => c.IsActive) .Where(c => c.Title == "Soups") .WithPartitionKey(_restaurantId) @@ -88,7 +81,7 @@ public async Task DeleteDatabaseAsync() string? input = Console.ReadLine(); if (input?.ToLower() == "y") { - bool deleted = await _menusContext.Database.EnsureDeletedAsync(); + bool deleted = await menusContext.Database.EnsureDeletedAsync(); string deletionInfo = deleted ? "deleted" : "not deleted"; Console.WriteLine($"database {deletionInfo}"); } diff --git a/2_Libs/EFCore/Intro/Intro.csproj b/2_Libs/EFCore/Intro/Intro.csproj index 51855e26..f91469db 100644 --- a/2_Libs/EFCore/Intro/Intro.csproj +++ b/2_Libs/EFCore/Intro/Intro.csproj @@ -12,13 +12,13 @@ --> - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/2_Libs/EFCore/LoadingRelatedData/LoadingRelatedData.csproj b/2_Libs/EFCore/LoadingRelatedData/LoadingRelatedData.csproj index 90885104..46c0315d 100644 --- a/2_Libs/EFCore/LoadingRelatedData/LoadingRelatedData.csproj +++ b/2_Libs/EFCore/LoadingRelatedData/LoadingRelatedData.csproj @@ -8,14 +8,14 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/2_Libs/EFCore/MigrationApp/MigrationApp.csproj b/2_Libs/EFCore/MigrationApp/MigrationApp.csproj index d6404801..1c8aaeb5 100644 --- a/2_Libs/EFCore/MigrationApp/MigrationApp.csproj +++ b/2_Libs/EFCore/MigrationApp/MigrationApp.csproj @@ -8,8 +8,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/2_Libs/EFCore/Models/Models.csproj b/2_Libs/EFCore/Models/Models.csproj index 4ff49212..79ea7f34 100644 --- a/2_Libs/EFCore/Models/Models.csproj +++ b/2_Libs/EFCore/Models/Models.csproj @@ -8,13 +8,13 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/2_Libs/EFCore/Queries/Queries.csproj b/2_Libs/EFCore/Queries/Queries.csproj index 1132db9e..ea95d925 100644 --- a/2_Libs/EFCore/Queries/Queries.csproj +++ b/2_Libs/EFCore/Queries/Queries.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/2_Libs/EFCore/Relationships/Relationships.csproj b/2_Libs/EFCore/Relationships/Relationships.csproj index 066fedb4..e38146c7 100644 --- a/2_Libs/EFCore/Relationships/Relationships.csproj +++ b/2_Libs/EFCore/Relationships/Relationships.csproj @@ -8,13 +8,13 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/2_Libs/EFCore/ScaffoldSample/ScaffoldSample.csproj b/2_Libs/EFCore/ScaffoldSample/ScaffoldSample.csproj index f52b1ae0..435f5a90 100644 --- a/2_Libs/EFCore/ScaffoldSample/ScaffoldSample.csproj +++ b/2_Libs/EFCore/ScaffoldSample/ScaffoldSample.csproj @@ -1,18 +1,18 @@ - + Exe - net7.0 + net8.0 enable enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/2_Libs/EFCore/Tracking/Tracking.csproj b/2_Libs/EFCore/Tracking/Tracking.csproj index 4ff49212..79ea7f34 100644 --- a/2_Libs/EFCore/Tracking/Tracking.csproj +++ b/2_Libs/EFCore/Tracking/Tracking.csproj @@ -8,13 +8,13 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/2_Libs/EFCore/Transactions/Transactions.csproj b/2_Libs/EFCore/Transactions/Transactions.csproj index 4ff49212..79ea7f34 100644 --- a/2_Libs/EFCore/Transactions/Transactions.csproj +++ b/2_Libs/EFCore/Transactions/Transactions.csproj @@ -8,13 +8,13 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + +