Backend/C_shape/WEBAPI/JWT/JWTdemo/Services/SqlContext.cs

26 lines
715 B
C#
Raw Normal View History

2024-05-06 14:09:39 +08:00
using Microsoft.EntityFrameworkCore;
using JWTdemo.Entities;
namespace JWTdemo.Services
{
public class SqlContext : DbContext
{
public SqlContext(DbContextOptions<SqlContext> options) : base(options)
{
//連接PostgreSQL
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
}
public DbSet<User>chatuser { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<User>().HasKey(o => new { o.Id }); //Primary Key
}
}
}