33 lines
1.4 KiB
C#
33 lines
1.4 KiB
C#
using System.Diagnostics;
|
|
using Buchhaltung;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BuchhaltungBlazor.Data;
|
|
|
|
public class BookingDb : DbContext {
|
|
public DbSet<Booking> Bookings { get; set; }
|
|
public DbSet<Category> Categories { get; set; }
|
|
public DbSet<SubCategory> SubCategories { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
|
|
const string connectionString = "server=woitschetzki.de;port=3308;database=buchhaltung;user=sascha;password=527646;SslMode=;SslCa=";
|
|
|
|
try {
|
|
optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)).EnableSensitiveDataLogging().EnableDetailedErrors();
|
|
}
|
|
catch (Exception exception) {
|
|
Debug.WriteLine(exception);
|
|
OnConfiguring(optionsBuilder);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder) {
|
|
base.OnModelCreating(modelBuilder);
|
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(BookingDb).Assembly);
|
|
modelBuilder.Entity<Booking>().Navigation(b => b.Category).AutoInclude();
|
|
new BookingConfiguration().Configure(modelBuilder.Entity<Booking>());
|
|
new CategoryConfiguration().Configure(modelBuilder.Entity<Category>());
|
|
new SubCategoryConfiguration().Configure(modelBuilder.Entity<SubCategory>());
|
|
}
|
|
} |