45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
|
using ASC.Core.Common.EF.Model;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|||
|
using Microsoft.Extensions.Options;
|
|||
|
|
|||
|
namespace ASC.Core.Common.EF.Context
|
|||
|
{
|
|||
|
public class TenantDbContext : BaseDbContext
|
|||
|
{
|
|||
|
public DbSet<DbTenant> Tenants { get; set; }
|
|||
|
public DbSet<User> Users { get; set; }
|
|||
|
public DbSet<UserSecurity> UserSecurity { get; set; }
|
|||
|
public DbSet<DbTenantVersion> TenantVersion { get; set; }
|
|||
|
public DbSet<DbTenantPartner> TenantPartner { get; set; }
|
|||
|
public DbSet<DbTenantForbiden> TenantForbiden { get; set; }
|
|||
|
public DbSet<DbCoreSettings> CoreSettings { get; set; }
|
|||
|
|
|||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|||
|
{
|
|||
|
modelBuilder.AddUser();
|
|||
|
|
|||
|
modelBuilder.AddCoreSettings();
|
|||
|
|
|||
|
modelBuilder.Entity<DbTenant>()
|
|||
|
.HasOne(r => r.Partner)
|
|||
|
.WithOne(r => r.Tenant)
|
|||
|
.HasForeignKey<DbTenantPartner>(r => new { r.TenantId })
|
|||
|
.HasPrincipalKey<DbTenant>(r => new { r.Id });
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static class TenantDbExtension
|
|||
|
{
|
|||
|
public static IServiceCollection AddTenantDbContextService(this IServiceCollection services)
|
|||
|
{
|
|||
|
services.TryAddScoped<DbContextManager<TenantDbContext>>();
|
|||
|
services.TryAddScoped<IConfigureOptions<TenantDbContext>, ConfigureDbContext>();
|
|||
|
services.TryAddScoped<TenantDbContext>();
|
|||
|
|
|||
|
return services;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|