Zahar: C# Transaction Script Code GeneratorT4 template generating C# typed stored procedure command classes for SQL Server Database. In the generated code, every stored procedure is represented by a dedicated command builder class, responsible for 1. Creating corresponding SqlCommand object 2. Creating typed wrapper around SqlDataReader objects 3. Creating an output values object for accessing the command output- and return- values. Features:- Multiple results - Table Value parameters - Output parameters Using generated classes:
C# Edit|Remove csharp var factory = new MyDbCmdBuilderFactory("Connection string goes here..."); var builder = factory.CreateDboMyStoredProcedureCmdBuilder();// [dbo].[MyStoredProcedure] // Set stored procedure parameters builder.Id = 10;// @Id INT builder.UntilDate = DateTime.Now;// @UntilDate DATETIME using (SqlConnection connection = factory.CreateConnection()) using (SqlCommand command = builder.BuildCommand(connection)) { await connection.OpenAsync(); using (SqlDataReader reader = await command.ExecuteReaderAsync()) { var current = builder.BuildRecordAdapter(reader); while (reader.Read()) { Console.WriteLine("{0}: {1}", current.ItemName, // = reader["ItemName"] current.ItemDescription// = reader["ItemDescription"] ); } reader.Close(); var output = builder.BuildOutputValues(command); Console.WriteLine(outout.RETURN_VALUE); } } var factory = new MyDbCmdBuilderFactory("Connection string goes here..."); var builder = factory.CreateDboMyStoredProcedureCmdBuilder();// [dbo].[MyStoredProcedure] // Set stored procedure parameters builder.Id = 10;// @Id INT builder.UntilDate = DateTime.Now;// @UntilDate DATETIME using (SqlConnection connection = factory.CreateConnection()) using (SqlCommand command = builder.BuildCommand(connection)) { await connection.OpenAsync(); using (SqlDataReader reader = await command.ExecuteReaderAsync()) { var current = builder.BuildRecordAdapter(reader); while (reader.Read()) { Console.WriteLine("{0}: {1}", current.ItemName, // = reader["ItemName"] current.ItemDescription// = reader["ItemDescription"] ); } reader.Close(); var output = builder.BuildOutputValues(command); Console.WriteLine(outout.RETURN_VALUE); } }
|