public ActionResult GenerateScript(ScriptModel model) { if (ModelState.IsValid && model.DacPac.ContentLength != 0) { var upgradeService = new DbUpgradeService(DbConnection.From(model.ConnectionString, model.DatabaseName)); var upgradeOptions = DbUpgradeOptions.From(model.IgnoreObjectTypes); upgradeOptions.IgnoreNotForReplication = model.IgnoreNotForReplication; upgradeOptions.DropConstraintsNotInSource = model.DropConstraintsNotInSource; upgradeOptions.DropIndexesNotInSource = model.DropIndexesNotInSource; upgradeOptions.VerifyDeployment = model.VerifyDeployment; using (var memoryStream = new MemoryStream()) { model.DacPac.InputStream.CopyTo(memoryStream); var dacpac = memoryStream.ToArray(); var upgradeScript = upgradeService.GenerateUpgradeScript(dacpac, upgradeOptions, model.DatabaseName); return(View("Publish", new PublishScript { Script = upgradeScript })); } } return(View()); }
public void GenerateScriptTest() { var dbConnection = DbConnection.From(modelConnection, "unemployment"); var service = new DbUpgradeService(dbConnection); var dacpac = service.GenerateDacPac(); var script = service.GenerateUpgradeScript(dacpac, DbUpgradeOptions.From(ObjectType.Users, ObjectType.Views, ObjectType.RoleMembership, ObjectType.Permissions, ObjectType.ExtendedProperties, ObjectType.StoredProcedures, ObjectType.Logins, ObjectType.DatabaseTriggers, ObjectType.ServerTriggers), "newdb"); Assert.IsNotNull(script); }