Basically, I want to use the "nice" Dapper syntax for a stored procedure, without having to manually use
exec MySproc @p1, @p2, @p3, @p4 and so on, but I need to be able to pass in a strongly typed object with various properties set and have this object be used to map the parameters. I know I can do this with an anonymous object, but the scenario I'm thinking of would be something like a complex search form where several fields can be searched, and the corresponding stored procedure can have quite a lot of parameters (many with defaults).
Ideally I'd want to be able to do something like this:
var cust = new Customer(); cust.FirstName = ... cust.LastName = ... // using .NET 3.5 so need to use ugly syntax :( var result = connection.Query<Customer>("MySproc", cust, null, false, null, CommandType.StoredProcedure).Single();
however, that doesn't work and throws an error because my Customer object may have a dozen or more properties, and I'm only looking for two in this case; Dapper seems to be just checking every property and assigning a value, assuming there is a corresponding parameter in the sproc when there might not be.
I can do something similar to this using PetaPoco (pass in a strongly-typed object or an anonymous object) but I'm looking for something a little more abstracted than PetaPoco is.
Is what I want to do possible in Dapper (or another micro-ORM? I cannot use NHibernate or a heavyweight ORM), or is there a way I'm overlooking to get the same functionality short of having to write an exec statement with what could be a dozen parameters?