| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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!;
- #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);
- base.OnModelCreating(modelBuilder);
- }
- #endregion
- }
- }
|