Basically, I want to use the βgoodβ Dapper syntax for the stored procedure, without having to manually use exec MySproc @p1, @p2, @p3, @p4
, etc., but I need to be able to pass a strongly typed object with different sets properties and this object is used to map parameters. I know that I can do this with an anonymous object, but the script that I think of will be something like a complex search form in which you can search for several fields, and there can be quite a few parameters in the corresponding stored procedure (many of them by default).
Ideally, I would like 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, this does not work and throws an error because my Customer object may have a dozen or more properties, in which case I am only looking for two; It seems that Dapper just checks each property and assigns a value, assuming that sproc has a corresponding parameter if that cannot be.
I can do something like this using PetaPoco (pass a strongly typed object or an anonymous object), but I'm looking for something more abstract than PetaPoco.
Do I want to do something possible in Dapper (or another micro-ORM? I canβt use NHibernate or heavyweight ORM), or is there a way that I skip the same functionality without having to write exec, which could be a dozen parameters ?
source share