114 lines
6.6 KiB
C#
114 lines
6.6 KiB
C#
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;
|
|
using WebApi_data_value.Models;
|
|
|
|
|
|
namespace Parking_space_WebAPI.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<User> parking_spaces_user { get; set; } = null!;
|
|
public DbSet<Parking_spaces_total_table> parking_spaces_total_table { get; set; } = null!; //<Parking_spaces_total_table> Model名稱 parking_spaces_total_table SQL名稱
|
|
public DbSet<Parking_spaces_violation_total_table> parking_spaces_violation_total_table { get; set; } = null!; //<Parking_spaces_total_table> Model名稱 parking_spaces_total_table SQL名稱
|
|
public DbSet<Parking_spaces_instant> parking_spaces_instant { get; set; } = null!; //<Parking_spaces_instant> Model名稱 parking_spaces_instant SQL名稱
|
|
public DbSet<Parking_spaces_history> parking_spaces_history { get; set; } = null!; //<Parking_spaces_history> Model名稱 parking_spaces_history SQL名稱
|
|
public DbSet<Parking_spaces_lcd_instand> parking_spaces_lcd_instand { get; set; } = null!; //<Parking_spaces_lcd_instand> Model名稱 parking_spaces_lcd_instand SQL名稱
|
|
|
|
public DbSet<Parking_spaces_cam> parking_spaces_cam { get; set; } = null!;
|
|
public DbSet<Violation_car_table> violation_car_table { get; set; } = null!;
|
|
|
|
//cam_roi
|
|
public DbSet<Parking_spaces_roi> parking_spaces_roi { get; set; } = null!;
|
|
public DbSet<Parking_spaces_roi_pass> parking_spaces_roi_pass { get; set; } = null!;
|
|
public DbSet<Parking_spaces_roi_violation> parking_spaces_roi_violation { get; set; } = null!;
|
|
public DbSet<Parking_spaces_roi_car_num_check> parking_spaces_roi_car_num_check { get; set; } = null!;
|
|
|
|
// cam_ptz
|
|
public DbSet<Parking_spaces_cam_ptz> parking_spaces_cam_ptz { get; set; } = null!;
|
|
public DbSet<Parking_spaces_cam_ptz_car_num_check> parking_spaces_cam_ptz_car_num_check { get; set; } = null!;
|
|
public DbSet<Parking_spaces_cam_ptz_pass> parking_spaces_cam_ptz_pass { get; set; } = null!;
|
|
public DbSet<Parking_spaces_cam_ptz_violation> parking_spaces_cam_ptz_violation { get; set; } = null!;
|
|
|
|
// 演算法
|
|
public DbSet<Parking_space_algorithm> parking_space_algorithm { get; set; } = null!;
|
|
|
|
//進入車輛
|
|
public DbSet<Yuntech_in_car_table> yuntech_in_car_table { get; set; } = null!;
|
|
|
|
//雲科校內相機
|
|
public DbSet<Yuntech_cam_total_table> yuntech_cam_total_table { get; set; } = null!;
|
|
public DbSet<Yuntech_cam> yuntech_cam { get; set; } = null!;
|
|
public DbSet<Yuntech_parking> yuntech_parking { get; set; } = null!;
|
|
|
|
// 雲科登記車輛名單
|
|
public DbSet<Yuntech_parking_user_list> yuntech_parking_user_list { get; set; } = null!;
|
|
|
|
//雲科月租與臨停
|
|
public DbSet<Yuntech_monthly_rent_number> yuntech_monthly_rent_number { get; set; } = null!;
|
|
|
|
//EL125車輛
|
|
public DbSet<El125_car_table> el125_car_table { get; set; } = null!;
|
|
|
|
// 新的剩餘車位與時間
|
|
public DbSet<ParkingLog> ParkingLogs { get; set; } = null!;
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
builder.Entity<User>().HasKey(o => new { o.id }); //Primary Key
|
|
builder.Entity<Parking_spaces_total_table>().HasKey(o => new { o.parking_spaces_name }); //Primary Key
|
|
builder.Entity<Parking_spaces_violation_total_table>().HasKey(o => new { o.parking_spaces_violation_name }); //Primary Key
|
|
builder.Entity<Parking_spaces_lcd_instand>().HasKey(o => new { o.lcd_ip }); //Primary Key
|
|
builder.Entity<Parking_spaces_instant>().HasKey(o => new { o.parking_spaces_name ,o.data_create_time }); //Primary Key
|
|
builder.Entity<Parking_spaces_history>().HasKey(o => new { o.parking_spaces_name, o.license_plate_number, o.data_create_time }); //Primary Key
|
|
builder.Entity<Violation_car_table>().HasKey(o => new { o.violation_location_name, o.license_plate_number, o.create_data_time }); //Primary Key
|
|
|
|
builder.Entity<Parking_spaces_roi>().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key
|
|
builder.Entity<Parking_spaces_roi_pass>().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key
|
|
builder.Entity<Parking_spaces_roi_violation>().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key
|
|
builder.Entity<Parking_spaces_roi_car_num_check>().HasKey(o => new { o.parking_spaces_name, o.data_create_time }); //Primary Key
|
|
|
|
builder.Entity<Parking_spaces_cam>().HasKey(o => new { o.parking_spaces_name }); //Primary Key
|
|
builder.Entity<Parking_spaces_cam_ptz>().HasKey(o => new { o.rtsp_url }); //Primary Key
|
|
builder.Entity<Parking_spaces_cam_ptz_car_num_check>().HasKey(o => new { o.rtsp_url,o.create_data_time }); //Primary Key
|
|
builder.Entity<Parking_spaces_cam_ptz_pass>().HasKey(o => new { o.rtsp_url, o.create_data_time }); //Primary Key
|
|
builder.Entity<Parking_spaces_cam_ptz_violation>().HasKey(o => new { o.rtsp_url, o.create_data_time }); //Primary Key
|
|
|
|
builder.Entity<Parking_space_algorithm>().HasKey(o => new { o.algorithm_serial_num }); //Primary Key
|
|
|
|
builder.Entity<Yuntech_in_car_table>().HasKey(o => new { o.in_time }); //Primary Key
|
|
|
|
builder.Entity<Yuntech_cam_total_table>().HasKey(o => new { o.location_name }); //Primary Key
|
|
builder.Entity<Yuntech_cam>().HasKey(o => new { o.ip }); //Primary Key
|
|
|
|
builder.Entity<Yuntech_parking>().HasKey(o => new { o.all_num }); //Primary Key
|
|
|
|
builder.Entity<Yuntech_monthly_rent_number>().HasKey(o => new { o.category }); //Primary Key
|
|
|
|
builder.Entity<Yuntech_parking_user_list>().HasKey(o => new { o.user_license_plate_number });//Primary Key
|
|
|
|
builder.Entity<El125_car_table>().HasKey(o => new { o.license_plate_number });//Primary Key
|
|
builder.Entity<ParkingLog>().HasKey(o => new { o.Id }); // 設定 ParkingLog 的主鍵
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |