Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically create C# wrapper classes around stored procedures

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 logic classes, some inline in in classic asp pages.

What I'd like to do is refactor this code, removing all the data access code into a few DAL classes.

All the data access is done through stored procedures (Microsoft SQL 2000). There are 300-400 of them.

It seems like there should be an automated way to analyse the store procedures, and automatically generate c# methods for each of them, mapping the Method parameters to the stored procedure parameters, with a method returning a datatable.

I don't have any experience with ORM products, and I'm not sure if what I'm looking for is a full blown ORM, or just a 3rd party utility that will help generate simple wrappers around the sp calls.

like image 975
Aheho Avatar asked Nov 14 '08 04:11

Aheho


1 Answers

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.

like image 79
Christian C. Salvadó Avatar answered Sep 28 '22 08:09

Christian C. Salvadó