|
|
|
|
@ -6,66 +6,49 @@ namespace Gremlin_BlazorServer.Data.DBClasses
|
|
|
|
|
{
|
|
|
|
|
public class GremlinDb : 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; }
|
|
|
|
|
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=";
|
|
|
|
|
const string connectionString = "server=woitschetzki.de;port=3306;database=regulus;user=root;password=lungretter1;SslMode=;SslCa=";
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)).EnableSensitiveDataLogging().EnableDetailedErrors();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine(ex);
|
|
|
|
|
//ChooseDB chooseDB = new();
|
|
|
|
|
//_ = chooseDB.ShowDialog();
|
|
|
|
|
Debug.WriteLine(e);
|
|
|
|
|
OnConfiguring(optionsBuilder);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigureAutoIncludeFor<T>(ModelBuilder modelBuilder) where T: class
|
|
|
|
|
{
|
|
|
|
|
var type = typeof(T);
|
|
|
|
|
|
|
|
|
|
foreach (var property in type.GetProperties())
|
|
|
|
|
{
|
|
|
|
|
if (typeof(IMetadata).IsAssignableFrom(property.PropertyType)
|
|
|
|
|
||
|
|
|
|
|
property.PropertyType.IsGenericType
|
|
|
|
|
&& typeof(IList<>).IsAssignableFrom(property.PropertyType.GetGenericTypeDefinition()))
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.Entity<T>().Navigation(e => property.GetValue(e)).AutoInclude();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// void ConfigureAutoIncludeFor<T>(ModelBuilder modelBuilder) where T: class
|
|
|
|
|
// {
|
|
|
|
|
// var type = typeof(T);
|
|
|
|
|
//
|
|
|
|
|
// foreach (var property in type.GetProperties())
|
|
|
|
|
// {
|
|
|
|
|
// if (typeof(IMetadata).IsAssignableFrom(property.PropertyType)
|
|
|
|
|
// ||
|
|
|
|
|
// property.PropertyType.IsGenericType
|
|
|
|
|
// && typeof(IList<>).IsAssignableFrom(property.PropertyType.GetGenericTypeDefinition()))
|
|
|
|
|
// {
|
|
|
|
|
// modelBuilder.Entity<T>().Navigation(e => property.GetValue(e)).AutoInclude();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
@ -76,6 +59,7 @@ namespace Gremlin_BlazorServer.Data.DBClasses
|
|
|
|
|
//TO BE TESTED!
|
|
|
|
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(GremlinDb).Assembly);
|
|
|
|
|
|
|
|
|
|
//AutoInclude all NavigationParameters in Entities
|
|
|
|
|
modelBuilder.Entity<Account>().Navigation(db => db.Contacts).AutoInclude();
|
|
|
|
|
modelBuilder.Entity<Account>().Navigation(db => db.AccountType).AutoInclude();
|
|
|
|
|
modelBuilder.Entity<Account>().Navigation(db => db.SubMarket).AutoInclude();
|
|
|
|
|
@ -87,11 +71,13 @@ namespace Gremlin_BlazorServer.Data.DBClasses
|
|
|
|
|
modelBuilder.Entity<Quote>().Navigation(db => db.Recipient).AutoInclude();
|
|
|
|
|
modelBuilder.Entity<Quote>().Navigation(db => db.LineItems).AutoInclude();
|
|
|
|
|
|
|
|
|
|
//Takes too much time
|
|
|
|
|
//modelBuilder.Entity<ProductLine>().Navigation(db => db.Products).AutoInclude();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Product>().Navigation(db => db.CustomDescription).AutoInclude();
|
|
|
|
|
modelBuilder.Entity<Product>().Navigation(db => db.ProductLine).AutoInclude();
|
|
|
|
|
|
|
|
|
|
//Generic AutoInclude method not yet working
|
|
|
|
|
//ConfigureAutoIncludeFor<Account>(modelBuilder);
|
|
|
|
|
|
|
|
|
|
////Fluent-Konfiguration einzeln für eine Entity aufrufen:
|
|
|
|
|
|