From e71ef3064182399412547e46c5db28771918471f Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Sat, 21 May 2022 17:16:40 +0200 Subject: [PATCH] DbContext Cleanup --- FoodsharingSiegen.Server/Data/FsContext.cs | 57 +++------------------- 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/FoodsharingSiegen.Server/Data/FsContext.cs b/FoodsharingSiegen.Server/Data/FsContext.cs index 86ecba6..1835ae1 100644 --- a/FoodsharingSiegen.Server/Data/FsContext.cs +++ b/FoodsharingSiegen.Server/Data/FsContext.cs @@ -8,69 +8,40 @@ namespace FoodsharingSiegen.Server.Data /// The fs context class (a. beging, 21.05.2022) /// /// - public class FsContext : DbContext + public sealed class FsContext : DbContext { #region Public Properties /// /// Gets or sets the value of the interactions (ab) /// - public DbSet Interactions { get; set; } + public DbSet? Interactions { get; set; } /// /// Gets or sets the value of the prospects (ab) /// - public DbSet Prospects { get; set; } + public DbSet? Prospects { get; set; } /// /// Gets or sets the value of the users (ab) /// - public DbSet Users { get; set; } + public DbSet? Users { get; set; } #endregion #region Setup/Teardown - /// - /// Initializes a new instance of the class - /// - public FsContext() : - base() - { - OnCreated(); - } - /// /// Initializes a new instance of the class /// /// The options (ab) - public FsContext(DbContextOptions options) : - base(options) + public FsContext(DbContextOptions options) : base(options) { - OnCreated(); + Database.EnsureCreated(); } #endregion - - #region Override OnConfiguring - - /// - /// Ons the configuring using the specified options builder (a. beging, 21.05.2022) - /// - /// The options builder - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - if (!optionsBuilder.IsConfigured || - (!optionsBuilder.Options.Extensions.OfType().Any(ext => !string.IsNullOrEmpty(ext.ConnectionString) || ext.Connection != null) && - !optionsBuilder.Options.Extensions.Any(ext => !(ext is RelationalOptionsExtension) && !(ext is CoreOptionsExtension)))) - { - } - - base.OnConfiguring(optionsBuilder); - } - - #endregion - + #region Public Method HasChanges /// @@ -79,19 +50,7 @@ namespace FoodsharingSiegen.Server.Data /// The bool public bool HasChanges() { - return ChangeTracker.Entries().Any(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Added || e.State == Microsoft.EntityFrameworkCore.EntityState.Modified || e.State == Microsoft.EntityFrameworkCore.EntityState.Deleted); - } - - #endregion - - #region Private Method OnCreated - - /// - /// Ons the created (a. beging, 21.05.2022) - /// - private void OnCreated() - { - // Database.EnsureCreated(); + return ChangeTracker.Entries().Any(e => e.State is EntityState.Added or EntityState.Modified or EntityState.Deleted); } #endregion