Backend/C_shape/WEBAPI/JWT/JWTdemo/Services/SqlContext.cs
Lin Weiting c07b6c1706 JWT
2024-05-06 14:09:39 +08:00

26 lines
715 B
C#

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
}
}
}