99 lines
3.0 KiB
C#
99 lines
3.0 KiB
C#
using FoodsharingSiegen.Contracts.Entity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
|
namespace FoodsharingSiegen.Server.Data
|
|
{
|
|
/// <summary>
|
|
/// The fs context class (a. beging, 21.05.2022)
|
|
/// </summary>
|
|
/// <seealso cref="DbContext"/>
|
|
public class FsContext : DbContext
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the interactions (ab)
|
|
/// </summary>
|
|
public DbSet<Interaction> Interactions { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the prospects (ab)
|
|
/// </summary>
|
|
public DbSet<Prospect> Prospects { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value of the users (ab)
|
|
/// </summary>
|
|
public DbSet<User> Users { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Setup/Teardown
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="FsContext"/> class
|
|
/// </summary>
|
|
public FsContext() :
|
|
base()
|
|
{
|
|
OnCreated();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="FsContext"/> class
|
|
/// </summary>
|
|
/// <param name="options">The options (ab)</param>
|
|
public FsContext(DbContextOptions<FsContext> options) :
|
|
base(options)
|
|
{
|
|
OnCreated();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Override OnConfiguring
|
|
|
|
/// <summary>
|
|
/// Ons the configuring using the specified options builder (a. beging, 21.05.2022)
|
|
/// </summary>
|
|
/// <param name="optionsBuilder">The options builder</param>
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured ||
|
|
(!optionsBuilder.Options.Extensions.OfType<RelationalOptionsExtension>().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
|
|
|
|
/// <summary>
|
|
/// Describes whether this instance has changes
|
|
/// </summary>
|
|
/// <returns>The bool</returns>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Ons the created (a. beging, 21.05.2022)
|
|
/// </summary>
|
|
private void OnCreated()
|
|
{
|
|
// Database.EnsureCreated();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |