public DbConnection CreateDbConnection(DbConnectionParameters dbConnectionParameters)
        {
            var connectionStringBuilder = new SqlConnectionStringBuilder
            {
                DataSource = dbConnectionParameters.DbServerUrl,
                InitialCatalog = dbConnectionParameters.DbInstanceName,
                IntegratedSecurity = true,
                MultipleActiveResultSets = true
            };

            if (!dbConnectionParameters.IsOsUser)
            {
                connectionStringBuilder.UserID = dbConnectionParameters.ConnectionUserName;
                connectionStringBuilder.Password = dbConnectionParameters.ConnectionUserPassword;
                connectionStringBuilder.IntegratedSecurity = false;
            }

            if (dbConnectionParameters.IsLocalDatabase)
            {
                connectionStringBuilder.AttachDBFilename = String.Format("{0}\\{1}.mdf", dbConnectionParameters.LocalDbFileCatalog, dbConnectionParameters.DbInstanceName);
            }

            return new SqlConnection(connectionStringBuilder.ToString());

        }
        public void CreateDataBase()
        {
            var contextFactory = new MsSqlDatabaseContextFactory();
            var parameters = new DbConnectionParameters 
            {
                DbServerUrl = "(localdb)\\v11.0",
                DbInstanceName = "TestCodeFirst",

                IsOsUser = true,
                ConnectionUserName = "",
                ConnectionUserPassword = ""
            };

            ModelContextBase context = contextFactory.CreateModelContext(contextFactory.CreateDbConnection(parameters));

            context.Database.CommandTimeout = 800;

            if (context.Database.Exists())
                context.Database.Delete();

            context.Database.Initialize(false);
        }