CODESMITH GENERATOR CODE
So what does the generated stored procedure wrapper code look like? Here’s a sample for a read-single-record sproc: Awareness of DbNull and CLR value type collisions. Automatic mapping of SQL OUT and INOUT params to method return types.Ħ. If the sproc takes in a smallint, you won’t get away with shoving a System.Int64 in there.ĥ. Automatic type mapping from SQL to CLR types and vice-versa. Automatic column mapping from sproc result sets to strongly typed domain objects.Ĥ. Compile-time failures when a stored procedure interface has changed and the application code hasn’t.ģ. There has since been some minor maintenance to it, but the overall time commitment has been exceedingly small. Start to finish was under three hours, and I had no CodeSmith experience before, other than poking around in the.
CODESMITH GENERATOR TRIAL
Some history: last summer I built a CodeSmith template to do the codegen, based on sample code from CodeSmith and some trial and error. The codegen implementation will work on just about any database (it is not team-specific), and if you adhere to a few basic rules with your sproc names, the generated code will be very nice. Classes with single-record and multiple-record column-to-property converters are generated for each table in the database as well. Methods are generated for every stored procedure, and multiple sproc calls can be used inside the same using block, as the SqlConnection is maintained for the undisposed life of the SomeDatabase instance. In the above code, the FooThing and SomeDatabase types are 100% generated code. Return FooThing.CreateFromDataReader(db.ReadFooThing(fooID)) Changes to the database scheme are automatically synchronized with your source by starting a new build or generating code manually.ĭavid Hayden compares the designer and the code generation approach in his post on Code Generation using CodeSmith - v4.1 - Visual Studio 2008 Support and LINQ to SQL Templates and comes to the following conclusion: Although the LINQ to SQL Visual Designer is very cool and very productive, I have been burned badly by Visual Designers in the past and would prefer to have each LINQ to SQL Entity in its own non-visual designer file just like every other class in Visual Studio.Using (SomeDatabase db = new SomeDatabase()).
CODESMITH GENERATOR GENERATOR
CodeSmith features a console generator and supports MSBuild. The generation of mappings may be incorporated into your build process.
You are in complete control of how mappings are generated.Although Visual Studio 2008 provides a visual designer, which helps to create SQL to LINQ mappings, the code generation approach of CodeSmith has some advantages:
The current release includes "updated LINQ templates to work with Visual Studio 2008 Beta 2".