using ASC.Core.Common.EF.Model; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; namespace ASC.Core.Common.EF.Context { public class TenantDbContext : BaseDbContext { public DbSet Tenants { get; set; } public DbSet Users { get; set; } public DbSet UserSecurity { get; set; } public DbSet TenantVersion { get; set; } public DbSet TenantPartner { get; set; } public DbSet TenantForbiden { get; set; } public DbSet TenantIpRestrictions { get; set; } public DbSet CoreSettings { get; set; } public TenantDbContext() { } public TenantDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.AddUser(); modelBuilder.AddCoreSettings(); modelBuilder.Entity() .HasOne(r => r.Partner) .WithOne(r => r.Tenant) .HasForeignKey(r => new { r.TenantId }) .HasPrincipalKey(r => new { r.Id }); } } public static class TenantDbExtension { public static IServiceCollection AddTenantDbContextService(this IServiceCollection services) { return services.AddDbContextManagerService(); } } }