AutoDispatching/AutoDispathingWork/ApplicationDbContext.cs
2024-08-10 23:43:46 +08:00

46 lines
1.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using WorkerService1.Domains;
using WorkerService1.Dto.Configuration;
namespace WorkerService1;
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
private static readonly ILoggerFactory _loggerFactory = new LoggerFactory();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseLoggerFactory(_loggerFactory);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var clientEntry = modelBuilder.Entity<ClientOptions>();
clientEntry.HasKey(x => x.Id);
var logEntry = modelBuilder.Entity<LogInfo>();
logEntry.HasKey(x => x.Id);
logEntry.HasIndex(x => x.CreateTime);
var polygonEntry = modelBuilder.Entity<Polygon>();
polygonEntry.HasKey(x => x.PolygonId);
polygonEntry.Property(x => x.Points).HasColumnType("jsonb");
polygonEntry.Property(x => x.RangeCameras).HasColumnType("jsonb");
var smsSendRecordEntry = modelBuilder.Entity<SmsSendRecord>();
smsSendRecordEntry.HasKey(x => x.Id);
smsSendRecordEntry.HasIndex(x => x.SendTime);
}
public DbSet<SmsSendRecord> SmsSendRecords { get; set; }
public DbSet<ClientOptions> ClientOptions { get; set; }
public DbSet<LogInfo> LogInfos { get; set; }
public DbSet<Polygon> Polygons { get; set; }
}