I\'ve inherited a rather large application that really could use some cleanup. There is data access code littered throughout the application. In code behinds, some in business l
Similar to Robert's suggestion, we've written our own version of Code Smith.
Our "Code Generator" has two parts: SQL & Classes.
SQL: Will generate the Update, Select & Delete stored procs.
C#: Will generate the classes and save the file as a .cs
We call: sp_MShelpcolumns 'tablename' to get a list of fields and data types and then do a replace.
Its not a perfect solution, but is very effective to getting the first 80% completed
If you have access to .NET Framework 3.5 and Linq to SQL, you can do it very easily, check this video:
LINQ to SQL: Using Stored Procedures
Using existing stored procedures and functions is easy with LINQ. We simply drag the stored procedures onto the O/R mapping surface and call them from the generated Data Context object.
I recommend you get a hold of Code Smith. The product includes a template for ORM and fully supports generating classes from DB Schemas (and I think Procs). You can then Code Gen all the objects you need.
Another option would be to use LINQ to SQL.
My approach would be to think higher level first- create your data access classes and methods the best way you can to fit your needs for your existing or new code base. Then, use the existing procedure calls for your new objects.
I do not think you should consider any form of mass automation for this task.
dragging and dropping the stored procedures onto a dataset design surface (in .net 2.0 and higher) generates a wrapping function
but if you have a lot of them to do, you might be better off using or writing a simple code generator
two options for this:
the latter can be maintained via the dataset design surface, but may be tricky to get generated right (the first time)
Not for sure, but seems like this is exactly what you were asking for.
http://www.codeproject.com/KB/database/SPGenerator.aspx