Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:56:25+00:00 2026-06-04T09:56:25+00:00

Basically, I want to use the nice Dapper syntax for a stored procedure, without

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:56:27+00:00Added an answer on June 4, 2026 at 9:56 am

    If you would like to specify the params you will need to do so explicitly:

    var result = connection.Query<Customer>("MySproc", 
         new {cust.Id, cust.Name}, // specify the params you want to give it.  
         null, 
         false, 
         null, 
         CommandType.StoredProcedure).Single();
    

    We do not do a sp_help params sniff for procs though you could potentially build a helper that does that and allows you to run: cust.ToProcParams('MySproc')

    Alternatively, if you want to build this param dynamically, you can use.

    var dp = new DynamicParameters(); 
    dp.Add("Id", cust.Id);
    dp.Add("Name", cust.Name);
    var result = connection.Query<Customer>("MySproc", 
             dp,
             null, 
             false, 
             null, 
             CommandType.StoredProcedure).Single();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically what i want is redirect al request to use HTTPS instead of http
Basically, I just want to know if its possible to use Nhibernate to migrate
Basically I want to replicate the page changing effect found here, at http://timvandamme.com/ But
I'm having a little problem with drawn lines on a canvas, Basically I want
this question is very similar to another post I basically want to use the
Basically what I want to do is print u'\u1001' , but I do not
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I basically want to be able to deploy multiple versions of the same EAR
I basically want to make things easier by just looping LinkButtons instead of making
I basically want to open a browser window from Word using VBA that does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.