ConnectionLogDBContext.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. namespace EVCB_OCPP.Domain
  2. {
  3. using EVCB_OCPP.Domain.Models.Database;
  4. using System;
  5. using System.Data.Entity;
  6. using System.Linq;
  7. public class ConnectionLogDBContext : DbContext
  8. {
  9. // 您的內容已設定為使用應用程式組態檔 (App.config 或 Web.config)
  10. // 中的 'ConnectionLogDBContext' 連接字串。根據預設,這個連接字串的目標是
  11. // 您的 LocalDb 執行個體上的 'EVCB_OCPP.Domain.ConnectionLogDBContext' 資料庫。
  12. //
  13. // 如果您的目標是其他資料庫和 (或) 提供者,請修改
  14. // 應用程式組態檔中的 'ConnectionLogDBContext' 連接字串。
  15. public ConnectionLogDBContext()
  16. : base("name=ConnectionLogDBContext")
  17. {
  18. Database.SetInitializer<ConnectionLogDBContext>(null);
  19. this.Configuration.AutoDetectChangesEnabled = false;
  20. this.Configuration.ValidateOnSaveEnabled = false;
  21. this.Configuration.AutoDetectChangesEnabled = false;
  22. this.Configuration.LazyLoadingEnabled = false;
  23. this.Database.CommandTimeout = 180;
  24. }
  25. /// <summary>
  26. /// DB coneection set
  27. /// </summary>
  28. public ConnectionLogDBContext(string conn)
  29. {
  30. this.Database.Connection.ConnectionString = conn;
  31. this.Configuration.AutoDetectChangesEnabled = false;
  32. this.Configuration.ValidateOnSaveEnabled = false;
  33. this.Configuration.AutoDetectChangesEnabled = false;
  34. this.Configuration.LazyLoadingEnabled = false;
  35. this.Database.CommandTimeout = 180;
  36. }
  37. // 針對您要包含在模型中的每種實體類型新增 DbSet。如需有關設定和使用
  38. // Code First 模型的詳細資訊,請參閱 http://go.microsoft.com/fwlink/?LinkId=390109。
  39. public virtual DbSet<MachineConnectionLog> MachineConnectionLog { get; set; }
  40. }
  41. //public class MyEntity
  42. //{
  43. // public int Id { get; set; }
  44. // public string Name { get; set; }
  45. //}
  46. }