internal static string CreateObjectsScript(StoreItemCollection itemCollection) { DdlSqlGnerator builder = new DdlSqlGnerator(); foreach (EntityContainer container in itemCollection.GetItems <EntityContainer>()) { var entitySets = container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name); //var schemas = new HashSet<string>(entitySets.Select(s => GetSchemaName(s))); //foreach (string schema in schemas.OrderBy(s => s)) //{ // // don't bother creating default schema // if (schema != "ingres") // { // builder.AppendCreateSchema(schema); // } //} foreach (EntitySet entitySet in container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name)) { builder.AppendCreateTable(entitySet); } foreach (AssociationSet associationSet in container.BaseEntitySets.OfType <AssociationSet>().OrderBy(s => s.Name)) { builder.AppendCreateForeignKeys(associationSet); } } return(builder.GetCommandText()); }
internal static string DropDatabaseScript(string databaseName) { var builder = new DdlSqlGnerator(); builder.AppendSql("drop database "); builder.AppendIdentifier(databaseName); return(builder.stringBuilder.ToString()); }
internal static string CreateDatabaseExistsScript(string databaseName) { var builder = new DdlSqlGnerator(); builder.AppendSql("SELECT Count(*) FROM "); builder.AppendSql("sys.databases"); builder.AppendSql(" WHERE [name]="); builder.AppendStringLiteral(databaseName); return(builder.stringBuilder.ToString()); }
internal static string CreateDatabaseScript(string databaseName, string dataFileName, string logFileName) { var builder = new DdlSqlGnerator(); builder.AppendSql("create database "); builder.AppendIdentifier(databaseName); if (null != dataFileName) { builder.AppendSql(" on primary "); builder.AppendFileName(dataFileName); builder.AppendSql(" log on "); builder.AppendFileName(logFileName); } return(builder.stringBuilder.ToString()); }
private void AppendCreateSchema(string schema) { AppendSql("if (schema_id("); AppendStringLiteral(schema); AppendSql(") is null) exec("); // need to create a sub-command and escape it as a string literal as well... DdlSqlGnerator schemaBuilder = new DdlSqlGnerator(); schemaBuilder.AppendSql("create schema "); schemaBuilder.AppendIdentifier(schema); AppendStringLiteral(schemaBuilder.stringBuilder.ToString()); AppendSql(");"); AppendNewLine(); }