| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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.Reflection;
- namespace Quadarax.Application.QLiberace.Base
- {
- [DbContextModuleAssignment(Constants.Modules.Base.Code)]
- public class QlbrcDbContext : DbContext
- {
- #region *** Mapped entities ***
- public DbSet<User> Users { get; set; }
- public DbSet<Tenant> Tenants { get; set; }
- public DbSet<Setting> Settings { get; set; }
- #endregion
-
- #region *** Constructors ***
- public QlbrcDbContext() : base()
- {
- }
- public QlbrcDbContext(DbContextOptions options) : base(options)
- {
- }
- #endregion
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- optionsBuilder.UseSqlServer(GetConnectionString());
- }
- private 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;
- }
- }
- }
|