Created
July 18, 2011 10:12
-
-
Save Tigraine/1089096 to your computer and use it in GitHub Desktop.
Arrow-Head anti-pattern in perfection..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void CreateSchema() | |
{ | |
using (var sqlConnection = new SqlConnection(connectionString)) | |
{ | |
sqlConnection.Open(); | |
using (var tx = sqlConnection.BeginTransaction()) | |
{ | |
foreach(var dto in dtos) | |
{ | |
try | |
{ | |
using (var command = sqlConnection.CreateCommand()) | |
{ | |
command.Transaction = tx; | |
var sb = new StringBuilder(); | |
sb.AppendLine(string.Format("IF EXISTS(SELECT * FROM sysobjects WHERE name='{0}' AND xtype = 'U') RETURN;", dto.Name)); | |
sb.AppendLine(builder.CreateSqlCreateStatementFromDto(dto)); | |
command.CommandText = sb.ToString(); | |
command.ExecuteNonQuery(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Could not create DtoTable: {0}\nMessage: {1}\nStackTrace: {2}", dto.FullName, ex.Message, ex.StackTrace); | |
tx.Rollback(); | |
throw; | |
} | |
} | |
tx.Commit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment