Exemple #1
0
        public static void Initialize(DeploymentLocation?deploymentLocation = null)
        {
            IDatabaseInitializer <ContextMaster> initializer = null;

            if (ContextMaster.HasInitializeBeenCalled)
            {
                // No need to throw an exception here.
            }
            else
            {
                ContextMaster.HasInitializeBeenCalled = true;

                try
                {
                    initializer = new CreateDatabaseIfNotExistsInitializer();
                    //initializer = new DropCreateDatabaseAlwaysInitializer();
                    //initializer = new DropCreateDatabaseIfModelChangesInitializer();

                    Database.SetInitializer <ContextMaster>(initializer);

                    using (var context = new ContextMaster(deploymentLocation: deploymentLocation ?? AffinityConfiguration.DeploymentLocation))
                    {
                        context.Database.Initialize(force: true);
                    }
                }
                catch (Exception exception)
                {
                    if (AffinityConfiguration.IsConfigurationDebug)
                    {
                        Debugger.Break();

                        if (AffinityConfiguration.DeploymentLocation != DeploymentLocation.Live)
                        {
                            Debug.Print(exception.ToString());
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Exemple #2
0
        static ContextMaster()
        {
            ContextMaster.HasInitializeBeenCalled = false;

            ContextMaster.Initialize();
        }