0

I'm evaluating using the Data Access Application Block 5.0 at work since we are married to stored procedures for the foreseeable future. I like the simplicity and the Mapper that is included in this, but what is turning me off is that there doesn't seem to be a way to specify an array of parameters, or even better some kind of "query by example" object, to the stored procedure call that will automatically create the parameters based on your criteria. Imagine a search customer feature, where you can specify one or more properties that need to be searched (let's assume we have a stored proc already created with nullable fields).

What I'd like to do is something like this:

var customerQuery = new { FirstName = "John", LastName = "Doe" }
var result = db.ExecuteSprocAccessor("SearchCustomers", customerQuery);

and have the anonymous object turned into the various SqlParameter objects.

Is something like this possible? The examples that I've seen on MSDN seem to just show specifying individual parameters, by hand, without any idea which parameter is which.

Wayne Molina
  • 19,158
  • 26
  • 98
  • 163

1 Answers1

0

Enterprise Library Data Access Application Block supports various mappers: Output Mappers, Result Set Mappers, and Parameter Mappers. Parameter Mappers are what you would be interested in in this case. If you are using SqlDatabase or OracleDatabase then a default parameter mapping mechanism is supported. The default mapping is simplistic and based on the position of parameters but you could create your own mappers if required.

Consider a stored procedure that takes 2 int parameters then a code snippet would look like:

var logs = db.ExecuteSprocAccessor<Log>("usp_getLogs", 
               new object[] { 1, -1 } // parameters as array
           ).ToList();

You could build some helper methods to create the appropriate object array.

Randy Levy
  • 22,566
  • 4
  • 68
  • 94