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

54 lines
1.6 KiB
C#
Raw Normal View History

2020-10-08 09:07:05 +00:00
using System;
using System.Collections.Generic;
using ASC.Common;
2020-02-17 08:58:14 +00:00
using ASC.Core.Common.EF.Model;
2020-10-08 09:07:05 +00:00
2019-12-12 15:24:47 +00:00
using Microsoft.EntityFrameworkCore;
namespace ASC.Core.Common.EF.Context
{
2020-10-06 11:38:15 +00:00
public class MySqlDbContext : DbContext { }
public class PostgreSqlDbContext : DbContext { }
public class DbContext : BaseDbContext
2019-12-12 15:24:47 +00:00
{
public DbSet<MobileAppInstall> MobileAppInstall { get; set; }
2019-12-13 13:05:24 +00:00
public DbSet<DbipLocation> DbipLocation { get; set; }
2019-12-17 08:27:38 +00:00
public DbSet<Regions> Regions { get; set; }
public DbContext()
{
}
public DbContext(DbContextOptions options) : base(options)
{
}
2020-10-06 11:38:15 +00:00
protected override Dictionary<Provider, Func<BaseDbContext>> ProviderContext
{
get
{
return new Dictionary<Provider, Func<BaseDbContext>>()
{
{ Provider.MySql, () => new MySqlDbContext() } ,
2020-10-08 09:07:05 +00:00
{ Provider.Postgre, () => new PostgreSqlDbContext() } ,
2020-10-06 11:38:15 +00:00
};
}
}
2019-12-12 15:24:47 +00:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
2020-09-06 22:49:03 +00:00
ModelBuilderWrapper
.From(modelBuilder, Provider)
.AddMobileAppInstall()
2020-10-05 10:02:28 +00:00
.AddDbipLocation();
2019-12-12 15:24:47 +00:00
}
}
2019-12-13 11:37:58 +00:00
public static class DbContextExtension
{
2020-02-17 08:58:14 +00:00
public static DIHelper AddDbContextService(this DIHelper services)
2019-12-13 11:37:58 +00:00
{
return services.AddDbContextManagerService<DbContext>();
}
}
2019-12-12 15:24:47 +00:00
}