2020-11-17 10:00:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using ASC.Common;
|
2020-09-15 13:11:05 +00:00
|
|
|
|
using ASC.Core.Common.EF.Model;
|
2020-10-12 16:23:15 +00:00
|
|
|
|
|
2020-09-15 13:11:05 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2020-10-12 16:23:15 +00:00
|
|
|
|
|
2020-09-15 13:11:05 +00:00
|
|
|
|
namespace ASC.Core.Common.EF.Context
|
|
|
|
|
{
|
2020-10-06 11:38:15 +00:00
|
|
|
|
public class MySqlTelegramDbContext : TelegramDbContext { }
|
|
|
|
|
public class PostgreSqlTelegramDbContext : TelegramDbContext { }
|
2020-09-15 13:11:05 +00:00
|
|
|
|
public class TelegramDbContext : BaseDbContext
|
|
|
|
|
{
|
|
|
|
|
public DbSet<TelegramUser> Users { get; set; }
|
|
|
|
|
|
|
|
|
|
public TelegramDbContext() { }
|
|
|
|
|
public TelegramDbContext(DbContextOptions<TelegramDbContext> 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 MySqlTelegramDbContext() } ,
|
2020-10-08 09:07:05 +00:00
|
|
|
|
{ Provider.Postgre, () => new PostgreSqlTelegramDbContext() } ,
|
2020-10-06 11:38:15 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-15 13:11:05 +00:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
2020-10-12 19:39:23 +00:00
|
|
|
|
ModelBuilderWrapper
|
2020-10-01 17:08:55 +00:00
|
|
|
|
.From(modelBuilder, Provider)
|
2020-10-05 10:11:15 +00:00
|
|
|
|
.AddTelegramUsers();
|
2020-09-15 13:11:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class TelegramDbContextExtension
|
|
|
|
|
{
|
|
|
|
|
public static DIHelper AddTelegramDbContextService(this DIHelper services)
|
|
|
|
|
{
|
|
|
|
|
return services.AddDbContextManagerService<TelegramDbContext>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|