| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using Microsoft.EntityFrameworkCore;
- using Quadarax.Application.QLiberace.Base.Entities;
- using Quadarax.Application.QLiberace.Common.Attributes;
- using Quadarax.Application.QLiberace.Common.Configuration;
- using Quadarax.Foundation.Core.Data.Domain;
- using Quadarax.Foundation.Core.Reflection;
- using System.Diagnostics;
- using Quadarax.Application.QLiberace.Base.Entities.DaoMapper;
- namespace Quadarax.Application.QLiberace.Base
- {
- [DbContextModuleAssignment(Constants.Modules.Base.Code)]
- public class QlbrcDbContext : DataDomain
- {
- #region *** Mapped entities ***
- public DbSet<User> Users { get; set; } = null!;
- public DbSet<Tenant> Tenants { get; set; } = null!;
- public DbSet<Setting> Settings { get; set; } = null!;
- public DbSet<TenantUser> TenantUsers { get; set; } = null!;
- public DbSet<TenantCurrency> TenantCurrencies { get; set; } = null!;
- public DbSet<TenantCountry> TenantCountries { get; set; } = null!;
- #endregion
-
- #region *** Constructors ***
- public QlbrcDbContext() : base(new DbContextOptions<QlbrcDbContext>())
- {
- }
- public QlbrcDbContext(DbContextOptions options) : base(options)
- {
- }
- #endregion
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- optionsBuilder.UseSqlServer(GetConnectionString()).LogTo(message => Debug.WriteLine("EFSQL>>" + message));;
- }
- protected string GetConnectionString()
- {
- var attr = AttributeQuery<DbContextModuleAssignmentAttribute>.Get(typeof(QlbrcDbContext));
- if (attr == null)
- throw new InvalidOperationException($"No connection string defined for DbContext {this.GetType().Name} or DbContextModuleAssignment is missing.");
- return OlbrcConfiguration.Get(attr.ModuleCode).ConnectionString;
- }
-
- #region *** Schema ***
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- new TenantDm().Map(modelBuilder);
- new UserDm().Map(modelBuilder);
- new SettingDm().Map(modelBuilder);
- new CurrencyDm().Map(modelBuilder);
- new CountryDm().Map(modelBuilder);
- new TenantUserDm().Map(modelBuilder);
- new TenantCurrencyDm().Map(modelBuilder);
- new TenantCountryDm().Map(modelBuilder);
- base.OnModelCreating(modelBuilder);
- }
- #endregion
- }
- }
|