DapperLib / DapperLib/Dapper

Get Parameter Names from non used DynamicParameters

Open
#1,113 0 comments 0 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 trying to log the command and the parameter names and values.

example:

				DynamicParameters parameters = new DynamicParameters(new
				{
					 DistribCode = distributorCode,
					 YardCode = string.Empty,
					 IncludeInactive = includeInactive

				});
				const string sp = "[brcSP_GetInvnDistributorsAndProductionYards]";
				_brcConnection.WriteDapperSQLLog(sp, parameters);

//____________________ WriteDapperSQLLog below
				StringBuilder logBuilder = new StringBuilder();
				if (Transaction.Current != null)
				{
					 logBuilder.Append("IN TRANSACTION!!!");
				}

				logBuilder.Append($"exec {storedProc}{Environment.NewLine}");
				if (param != null)
				{
					 int index = 0;
					 if (typeof(DynamicParameters) == param.GetType())
					 {
						  DynamicParameters parameters = param as DynamicParameters;
						  foreach (string name in parameters.ParameterNames)
						  {
								dynamic value = parameters.Get<dynamic>(name);
								logBuilder.Append($" @{name} = {value?.ToString() ?? string.Empty}{((index++ == parameters.ParameterNames.Count() - 1) ? string.Empty : ",")}{Environment.NewLine}");
						  }
						  					 }
					 else

ParameterNames is 0 length.

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 reproducing the shown DynamicParameters construction and inspect the ParameterNames entry point, including how values are retrieved with Get. Confirm why ParameterNames is empty for these parameters, then add coverage and ensure the parameter names and values can be logged as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.