Blame view

Vrh.iScheduler.Report/DAL/SchedulerReportDbContext.cs 3.12 KB
ab9f2fbe   Schwirg László   Add project files.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  /*
  Update-Database -TargetMigration $InitialDatabase
  Add-Migration -name FirstMigration -Force -Verbose
  Add-Migration -name Update03 -Force -Verbose
  Update-Database
  */
  
  namespace Vrh.iScheduler.Report
  {
      using System.Data.Entity;
  
      using Vrh.XmlProcessing;
      using Lib.Migrations;
      using System.Data.Entity.ModelConfiguration.Conventions;
  
      /// <summary>
      /// iSchedulerReport DBContext osztálya.
      /// </summary>
      public class SchedulerReportDbContext : DbContext
      {
          private static bool m_WasDBMigrationCheck = false;
  
          #region Constructors
          /// <summary>
          /// DBContext példány elkészítése az alapértelmezett kapcsolati sztring név felhasználásával.
          /// </summary>
          public SchedulerReportDbContext() : this(ActiveConnectionString)
          //public SchedulerReportDbContext() : this(@"data source = 192.168.77.150\SQLEXPRESS;initial catalog = LearALMNew; user id = sa; password=Vrh@54321;multipleactiveresultsets=True;Connection Timeout = 3600")
          {
              Configuration.LazyLoadingEnabled = true;
              if (!m_WasDBMigrationCheck)
              {
                  Database.SetInitializer(new MigrateDatabaseToLatestVersion<SchedulerReportDbContext, Configuration>(true));
                  m_WasDBMigrationCheck = true;
              }
          }
          /// <summary>
          /// DBContext példány elkészítése egy megadott szabványos és érvényes kapcsolati sztring felhasználásával.
          /// </summary>
          public SchedulerReportDbContext(string connectionString) : base(connectionString)
          {
              Configuration.LazyLoadingEnabled = true;
              if (!m_WasDBMigrationCheck)
              {
                  Database.SetInitializer(new MigrateDatabaseToLatestVersion<SchedulerReportDbContext, Configuration>(true));
                  m_WasDBMigrationCheck = true;
              }
          }
          #endregion Constructors
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              const string SCHEMANAME = "iSchedulerReports";
              modelBuilder.HasDefaultSchema(SCHEMANAME);
              modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
              try { RegisterConnectionString(ConnectionStringStore.GetSQL(SRConstants.DEFAULT_CONNECTIONSTRINGNAME)); } catch { }
          }
          private static string ActiveConnectionString = null;
          /// <summary>
          /// Egy connectionstring regisztrálása a DBContext-be. A hívás után az 
          /// összes paraméter nélküli konstruktor hívás az itt megadott kapcsolatleíróra vonatkozik.
          /// </summary>
          /// <param name="cs"></param>
          public static void RegisterConnectionString(string cs) { ActiveConnectionString = cs; }
  
          /// <summary>
          /// A report csomagokat tartalmazó táblázat.
          /// </summary>
          public IDbSet<SchedulerReportPackage> SchedulerReportPackages { get; set; }
  
          /// <summary>
          /// Egy report csomag elemeit tartalmazó táblázat.
          /// </summary>
          public IDbSet<SchedulerReportPackageItem> SchedulerReportPackageItems { get; set; }
      }
  }