DapperLib / DapperLib/Dapper

Please expose DynamicParameters.parameters

Open
#849 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

My scenario :
Logging the database access, including parameters infos, like this:

// business logic layer
public class DemoBLL
{
  public void M1(p1, p2, p3)
  {
    DynamicParameters dynPars = new DynamicParameters();
    if(...)
      dynPars.Add(parname1, parvalue1);
    if(...)
      dynPars.Add(parname2, parvalue2);

    QueryL(conn.Query(sql, dynPars,...); 
  }

  public void M2(p4, ...)
  {
    DynamicParameters dynPars = new DynamicParameters();
    if(...)
      dynPars.Add(...);
    if(...)
      dynPars.Add(...);

    QueryL(conn.Query(sql, dynPars,...); 
  }
}

// data access layer
public class DemoDAL
{
  public void QueryL(sql, dynPars,...)
  {
    // log the query infos
    logger.Info("Sql Text:" + sql);
    
    // I wish i could do like this
    foreach (var dp in dynPars.Parameters) // but there's no public 'Parameters' member, so these code won't effect
    {
      sb.AppendFormat("{{Name:{0}, Type:{1}, Value:{2}, Direction:{3}}}, ", 
          dp.Value.Name, dp.Value.DbType, 
          Convert.ToString(dp.Value.Value), 
          dp.Value.ParameterDirection);
    }
    
    conn.Query(sql, dynPars)
  }
}

I hope if we could foreach DynamicParameters.parameters, that will be very very useful!

Another scenarios:
https://github.com/StackExchange/Dapper/issues/304

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 by locating the DynamicParameters class and inspect how its parameters are stored and exposed. Add a public Parameters member that supports the foreach usage shown in the issue, then verify callers can read each parameter's name, type, value, and direction without changing query execution.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.