DocSpace-buildtools/common/ASC.Core.Common/EF/Context/CoreDbContext.cs

40 lines
1.3 KiB
C#
Raw Normal View History

2019-11-29 12:26:53 +00:00
using Microsoft.EntityFrameworkCore;
2019-11-29 13:47:05 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
2019-11-29 12:26:53 +00:00
namespace ASC.Core.Common.EF
{
public class CoreDbContext : BaseDbContext
{
public DbSet<EFTariff> Tariffs { get; set; }
public DbSet<EFButton> Buttons { get; set; }
2019-11-29 13:47:05 +00:00
public DbSet<Acl> Acl { get; set; }
2019-12-02 09:12:16 +00:00
public DbSet<DbQuota> Quotas { get; set; }
public DbSet<DbQuotaRow> QuotaRows { get; set; }
2019-11-29 12:26:53 +00:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
2019-11-29 13:47:05 +00:00
modelBuilder.AddAcl();
2019-11-29 12:26:53 +00:00
modelBuilder.Entity<EFButton>()
.HasKey(c => new { c.TariffId, c.PartnerId });
2019-12-02 09:12:16 +00:00
modelBuilder.Entity<DbQuotaRow>()
.HasKey(c => new { c.Tenant, c.Path });
2019-11-29 12:26:53 +00:00
}
}
2019-11-29 13:47:05 +00:00
public static class CoreDbExtension
{
public static IServiceCollection AddCoreDbContextService(this IServiceCollection services)
{
services.TryAddScoped<DbContextManager<CoreDbContext>>();
services.TryAddScoped<IConfigureOptions<CoreDbContext>, ConfigureDbContext>();
services.TryAddScoped<CoreDbContext>();
return services;
}
}
2019-11-29 12:26:53 +00:00
}