Gremlin/Gremlin_BlazorServer/Data/DBClasses/GremlinContext.cs

80 lines
3.1 KiB
C#

using Gremlin_BlazorServer.Data.EntityClasses;
using Gremlin_BlazorServer.Utilities;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
namespace Gremlin_BlazorServer.Data.DBClasses
{
public class GremlinContext : DbContext
{
public DbSet<Contact> Contacts { get; set; }
public DbSet<Account> Accounts { get; set; }
public DbSet<Quote> Quotes { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<LineItem> LineItems { get; set; }
public DbSet<CustomDescription> CustomDescriptions { get; set; }
public DbSet<ProductLine> ProductLines { get; set; }
public DbSet<AccountType> AccountTypes { get; set; }
public DbSet<SubMarket> SubMarkets { get; set; }
public DbSet<RUSettings> RUSettings { get; set; }
public DbSet<RegisteredUser> RegisteredUser { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//string connectionString = $"server={Properties.Settings.Default.server};" +
// $"port={Properties.Settings.Default.port};" +
// $"database={Properties.Settings.Default.database};" +
// $"user={Properties.Settings.Default.user};" +
// $"password={Encryption.ToInsecureString(Encryption.DecryptString(Properties.Settings.Default.password))};" +
// $"SslMode={Properties.Settings.Default.SslMode};" +
// $"SslCa={Properties.Settings.Default.SslCA}";
string connectionString = $"server=woitschetzki.de;" +
$"port=3306;" +
$"database=regulus;" +
$"user=root;" +
$"password=lungretter1;" +
$"SslMode=;" +
$"SslCa=";
try
{
_ = optionsBuilder
.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))
//mySqlOptionsAction => mySqlOptionsAction.CharSetBehavior(Pomelo.EntityFrameworkCore.MySql.Infrastructure.CharSetBehavior.NeverAppend)).EnableDetailedErrors()
.EnableSensitiveDataLogging()
.EnableDetailedErrors();
}
catch (Exception ex)
{
Debug.WriteLine(ex);
//ChooseDB chooseDB = new();
//_ = chooseDB.ShowDialog();
OnConfiguring(optionsBuilder);
throw;
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//wozu dient die folgende Zeile?
base.OnModelCreating(modelBuilder);
////alle Fluent-Konfigurationen aufrufen:
//TO BE TESTED!
_ = modelBuilder.ApplyConfigurationsFromAssembly(typeof(GremlinContext).Assembly);
////Fluent-Konfiguration einzeln für eine Entity aufrufen:
//new AccountConfiguration().Configure(modelBuilder.Entity<Account>());
//new ContactConfiguration().Configure(modelBuilder.Entity<Contact>());
//new QuoteConfiguration().Configure(modelBuilder.Entity<Quote>());
//new ProductConfiguration().Configure(modelBuilder.Entity<Product>());
//new LineItemConfiguration().Configure(modelBuilder.Entity<LineItem>());
//new CustomDescriptionConfiguration().Configure(modelBuilder.Entity<CustomDescription>());
//new ProductLineConfiguration().Configure(modelBuilder.Entity<ProductLine>());
//new AccountTypeConfiguration().Configure(modelBuilder.Entity<AccountType>());
//new SubMarketConfiguration().Configure(modelBuilder.Entity<SubMarket>());
}
}
}