Exemple #1
0
        /// <summary>
        /// Retrieves an instance of GatewayMgmtContext from the appropriate storage container or
        /// creates a new instance and stores that in a container.
        /// </summary>
        /// <returns>An instance of GatewayMgmtContext.</returns>
        public static GatewayMgmtContext GetDataContext()
        {
            var dataContextStorageContainer = DataContextStorageFactory <GatewayMgmtContext> .CreateStorageContainer();

            var dataContext = dataContextStorageContainer.GetDataContext();

            if (dataContext == null)
            {
                dataContext = new GatewayMgmtContext();
                dataContextStorageContainer.Store(dataContext);
            }
            return(dataContext);
        }
Exemple #2
0
 /// <summary>
 /// Sets the IDatabaseInitializer for the application.
 /// </summary>
 /// <param name="dropDatabaseIfModelChanges">When true, uses the MyDropCreateDatabaseIfModelChanges to recreate the database when necessary.
 /// Otherwise, database initialization is disabled by passing null to the SetInitializer method.
 /// </param>
 public static void Init(bool dropDatabaseIfModelChanges)
 {
     if (dropDatabaseIfModelChanges)
     {
         Database.SetInitializer(new MyDropCreateDatabaseIfModelChanges());
         using (var db = new GatewayMgmtContext())
         {
             db.Database.Initialize(false);
         }
     }
     else
     {
         Database.SetInitializer <GatewayMgmtContext>(null);
     }
 }