Question

I am trying to create a dynamic stored procedure caller function (that would be setup as an endpoint in a .NET 4.0 WebApi Service).

Here are the facts:

  • I know I'm always going to be calling a stored procedure that has one integer parameter.

  • I know I'm going to be adding more stored procedures in the future, so I'd rather code it once in the DAL and let things be dynamic enough that if I kept a table in the database with all the possible stored procedure names I don't have to keep changing the DAL code every time I add a stored procedure.

  • I tried to use Linq, but it seems that if I were to use a generic definition, I'd end up with code changes that I'd have to do in the DAL as shown here: http://givemelifo.blogspot.com/2012/05/dynamically-selecting-records-through.html

So the bottom line is that I'm trying to call a stored procedure without having its or what it'll return. So no DBML file that has all those stored procedures defined.

Currently I have those stored procedures in a DBML and they're pretty cumbersome to keep updated and they're pretty rigid as they have the returned fields defined in some metadata/.designer file. Not so dynamic.

I know there is probably a way in some kind of dataAdapters implementation, if you can just point me in the right directions. Just keep in mind that whatever solution you suggest, I'd have to be able to convert it into a list and return it as a this.Request.CreateResponse(HttpStatusCode.OK, HttpResponseMessage);

Please help!

Was it helpful?

Solution

You must choose the best tool to your problem and not shoehorn the tool into the problem. :D

I think plain old ADO.NET will work for you.

You might also look into how SQL Server exposes stored procedures via HTTP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top