50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace IRaCIS.Core.Test.PGModelFolder;
|
|
|
|
public partial class PGContext : DbContext
|
|
{
|
|
public PGContext()
|
|
{
|
|
}
|
|
|
|
public PGContext(DbContextOptions<PGContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public virtual DbSet<Subject> Subjects { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
=> optionsBuilder.UseNpgsql("Host=106.14.89.110;Port=5432;Username=sa;Password=pgsql_pwd;Database=Test6_PG");
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
|
|
if (base.Database.IsNpgsql())
|
|
{
|
|
modelBuilder.HasPostgresExtension("uuid-ossp");
|
|
|
|
//保证pgsql 生成的时间默认为timestamp 而不是 timestamp with time zone
|
|
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
|
{
|
|
foreach (var property in entityType.GetProperties())
|
|
{
|
|
if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?))
|
|
{
|
|
property.SetColumnType("timestamp without time zone");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
}
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
|
}
|