2025-02-19 20:10:10 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.Extensions.Configuration.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using TCM_API.Models;
|
|
|
|
|
using TCM_API.Entities;
|
2025-02-20 21:28:22 +08:00
|
|
|
|
using TCM_API.Models.manage;
|
2025-02-19 20:10:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace TCM_API.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<E_table_v> e_table_v { get; set; } = null!;
|
|
|
|
|
//public DbSet<Test_0525> test_0525 { get; set; } = null!; //<Test_0330> Model名稱 test_0330 SQL名稱
|
|
|
|
|
public DbSet<User> user_table { get; set; } = null!;
|
|
|
|
|
public DbSet<Company_detail_table> company_detail_table { get; set; } = null!;
|
2025-02-20 21:28:22 +08:00
|
|
|
|
public DbSet<Health_detail_table> health_detail_table { get; set; } = null!;
|
2025-02-19 20:10:10 +08:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
base.OnModelCreating(builder);
|
|
|
|
|
//builder.Entity<Test_0525>().HasKey(o => new { o.user_id }); //Primary Key
|
|
|
|
|
builder.Entity<User>().HasKey(o => new { o.id }); //Primary Key
|
|
|
|
|
builder.Entity<Company_detail_table>().HasKey(o => new { o.guid });
|
2025-02-20 21:28:22 +08:00
|
|
|
|
builder.Entity<Health_detail_table>().HasKey(o => new { o.guid });
|
2025-02-19 20:10:10 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|