DapperLib / DapperLib/Dapper

Telling Dapper not to use properties as parameters to create stored procedure

Open
#598 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

I am using the following notation to call a stored procedure:

                        dbConnection.Open();
                        result = dbConnection.ExecuteScalar<int>(typeof(T).Name + "_c",
                            obj, commandType: CommandType.StoredProcedure);

This works with one caveat: You must explicitly name every property in your class as a parameter to the stored procedure. If you don't, you get bizarre errors back.

This can be cumbersome in some cases when the class has view properties that are not in the table corresponding to that class in the database, or a lot of fields are not used in an initial insert and have default values in the table definition, but may be used later on, or are updated automatically by a trigger.

I would love to be able to annotate the class with an attribute that tells Dapper not to include these properties as input parameters to the stored procedure to limit the list of parameters in a stored procedure to only those necessary.

Is there a way to do this, and if not, can we update Dapper to support this?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ExecuteScalar call with CommandType.StoredProcedure and trace how Dapper turns object properties into stored-procedure parameters. Define how an attribute would exclude selected properties, then add coverage for view or unused properties and verify that only intended parameters are passed.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.