using FoodsharingSiegen.Contracts.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace FoodsharingSiegen.Server.Data
{
///
/// The fs context class (a. beging, 21.05.2022)
///
///
public class FsContext : DbContext
{
#region Public Properties
///
/// Gets or sets the value of the interactions (ab)
///
public DbSet Interactions { get; set; }
///
/// Gets or sets the value of the prospects (ab)
///
public DbSet Prospects { get; set; }
///
/// Gets or sets the value of the users (ab)
///
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)
{
OnCreated();
}
#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
///
/// Describes whether this instance has changes
///
/// 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();
}
#endregion
}
}