using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Configuration.Json; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Parking_space_WebAPI.Models; using Parking_space_WebAPI.Entities; namespace Parking_space_WebAPI.Services { public class SqlContext : DbContext { public SqlContext(DbContextOptions options) : base(options) { //連接PostgreSQL AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); } //public DbSet e_table_v { get; set; } = null!; public DbSet parking_spaces_user { get; set; } = null!; public DbSet parking_spaces_total_table { get; set; } = null!; // Model名稱 parking_spaces_total_table SQL名稱 public DbSet parking_spaces_violation_total_table { get; set; } = null!; // Model名稱 parking_spaces_total_table SQL名稱 public DbSet parking_spaces_instant { get; set; } = null!; // Model名稱 parking_spaces_instant SQL名稱 public DbSet parking_spaces_history { get; set; } = null!; // Model名稱 parking_spaces_history SQL名稱 public DbSet parking_spaces_lcd_instand { get; set; } = null!; // Model名稱 parking_spaces_lcd_instand SQL名稱 public DbSet parking_spaces_cam { get; set; } = null!; public DbSet violation_car_table { get; set; } = null!; //cam_roi public DbSet parking_spaces_roi { get; set; } = null!; public DbSet parking_spaces_roi_pass { get; set; } = null!; public DbSet parking_spaces_roi_violation { get; set; } = null!; public DbSet parking_spaces_roi_car_num_check { get; set; } = null!; // cam_ptz public DbSet parking_spaces_cam_ptz { get; set; } = null!; public DbSet parking_spaces_cam_ptz_car_num_check { get; set; } = null!; public DbSet parking_spaces_cam_ptz_pass { get; set; } = null!; public DbSet parking_spaces_cam_ptz_violation { get; set; } = null!; // 演算法 public DbSet parking_space_algorithm { get; set; } = null!; //大門口 public DbSet yuntech_in_car_table { get; set; } = null!; //雲科校內相機 public DbSet yuntech_cam_total_table { get; set; } = null!; public DbSet yuntech_cam { get; set; } = null!; protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity().HasKey(o => new { o.id }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_violation_name }); //Primary Key builder.Entity().HasKey(o => new { o.lcd_ip }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name ,o.data_create_time }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name, o.license_plate_number, o.data_create_time }); //Primary Key builder.Entity().HasKey(o => new { o.violation_location_name, o.license_plate_number, o.create_data_time }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key builder.Entity().HasKey(o => new { o.parking_spaces_name }); //Primary Key builder.Entity().HasKey(o => new { o.rtsp_url }); //Primary Key builder.Entity().HasKey(o => new { o.rtsp_url,o.create_data_time }); //Primary Key builder.Entity().HasKey(o => new { o.rtsp_url, o.create_data_time }); //Primary Key builder.Entity().HasKey(o => new { o.rtsp_url, o.create_data_time }); //Primary Key builder.Entity().HasKey(o => new { o.algorithm_serial_num }); //Primary Key builder.Entity().HasKey(o => new { o.in_time }); //Primary Key builder.Entity().HasKey(o => new { o.location_name }); //Primary Key builder.Entity().HasKey(o => new { o.ip }); //Primary Key } } }