MainDBContext.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. namespace EVCB_OCPP.Domain
  2. {
  3. using EVCB_OCPP.Domain.Models.Database;
  4. using Microsoft.EntityFrameworkCore;
  5. using System;
  6. using System.Linq;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. public class MainDBContext : DbContext
  10. {
  11. // 您的內容已設定為使用應用程式組態檔 (App.config 或 Web.config)
  12. // 中的 'MainDBContext' 連接字串。根據預設,這個連接字串的目標是
  13. // 您的 LocalDb 執行個體上的 'EVCB_OCPP.Domain.MainDBContext' 資料庫。
  14. //
  15. // 如果您的目標是其他資料庫和 (或) 提供者,請修改
  16. // 應用程式組態檔中的 'MainDBContext' 連接字串。
  17. public MainDBContext() : base()
  18. {
  19. //this.Configuration.LazyLoadingEnabled = false;
  20. //this.Database.CommandTimeout = 180;
  21. }
  22. /// <summary>
  23. /// DB coneection set
  24. /// </summary>
  25. //public MainDBContext(string conn)
  26. //{
  27. // this.Database.Connection.ConnectionString = conn;
  28. // this.Configuration.LazyLoadingEnabled = false;
  29. // this.Database.CommandTimeout = 180;
  30. //}
  31. public MainDBContext(DbContextOptions options) : base(options)
  32. {
  33. }
  34. // 針對您要包含在模型中的每種實體類型新增 DbSet。如需有關設定和使用
  35. // Code First 模型的詳細資訊,請參閱 http://go.microsoft.com/fwlink/?LinkId=390109。
  36. public virtual DbSet<OCMF> OCMF { get; set; }
  37. public virtual DbSet<ConnectorStatus> ConnectorStatus { get; set; }
  38. public virtual DbSet<Customer> Customer { get; set; }
  39. public virtual DbSet<Machine> Machine { get; set; }
  40. public virtual DbSet<MachineConfiguration> MachineConfigurations { get; set; }
  41. public virtual DbSet<MachineError> MachineError { get; set; }
  42. public virtual DbSet<MachineOperateRecord> MachineOperateRecord { get; set; }
  43. public virtual DbSet<MachineVersionFile> MachineVersionFile { get; set; }
  44. public virtual DbSet<ServerMessage> ServerMessage { get; set; }
  45. public virtual DbSet<TransactionRecord> TransactionRecord { get; set; }
  46. public virtual DbSet<UploadFile> UploadFile { get; set; }
  47. protected override void OnModelCreating(ModelBuilder modelBuilder)
  48. {
  49. modelBuilder.Entity<Machine>().Property(x => x.RatedPower).HasPrecision(6, 2);
  50. modelBuilder.Entity<Machine>().Property(x => x.Longitude).HasPrecision(10, 6);
  51. modelBuilder.Entity<Machine>().Property(x => x.Latitude).HasPrecision(10, 6);
  52. modelBuilder.Entity<ConnectorStatus>().Property(x => x.TotalEnergy).HasPrecision(10, 2);
  53. base.OnModelCreating(modelBuilder);
  54. }
  55. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  56. {
  57. //optionsBuilder.UseSqlServer("data source=172.1.2.187;initial catalog=StandardOCPP_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework");
  58. base.OnConfiguring(optionsBuilder);
  59. }
  60. }
  61. }