DapperLib / DapperLib/Dapper

Unable to mapped underscore column in dapper extension

Open
#1,825 3 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

Hi, I have a user data model containing some underscore columns but I'm unable to insert, update and get records using the dapper extension library it is throwing reflection error below you can see:

at DapperExtensions.ReflectionHelper.GetParameter(Type entityType, ISqlGenerator sqlGenerator, String propertyName, Object value)
at DapperExtensions.DapperImplementor.AddParameter[T](T entity, DynamicParameters parameters, IMemberMap prop, Boolean useColumnAlias)
at DapperExtensions.DapperImplementor.GetDynamicParameters[T](T entity, IClassMapper classMap, IList1 sequenceColumn, IList1 foreignKeys, IList1 ignoredColumns, Boolean useColumnAlias) at DapperExtensions.DapperImplementor.GetDynamicParameters[T](IClassMapper classMap, T entity, Boolean useColumnAlias) at DapperExtensions.DapperImplementor.InternalUpdate[T](IDbConnection connection, T entity, IClassMapper classMap, IPredicate predicate, IDbTransaction transaction, IList1 cols, Nullable1 commandTimeout, Boolean ignoreAllKeyProperties) at DapperExtensions.DapperAsyncImplementor.<InternalUpdateAsync>d__151.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DapperExtensions.DapperAsyncImplementor.d__161.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at DapperExtensions.DapperAsyncImplementor.<UpdateAsync>d__31.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DapperExtensions.AsyncDatabase.d__81.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()

User Data Model:
public class Permission
{
public Guid Id { get; set; }
public string permission_code { get; set; }
public string role_code { get; set; }
public bool HasPermission { get; set; }
public string PermissionStatus { get; set; }
public string addl_data { get; set; }
}

await db.Update(roleView, null, true);

Also, I set this property before and after the connection opened but this is not working throwing the above exception:

IDbConnection con = CreateConnection();
if (con == null)
throw new ApplicationException("CreateConnection function did not return a valid connection");
DefaultTypeMap.MatchNamesWithUnderscores = true;
con.Open();

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 with the ReflectionHelper.GetParameter call in the stack trace and inspect how DefaultTypeMap.MatchNamesWithUnderscores is used during the Update path. Reproduce the failure with the shown Permission model and underscore-named properties; done means the relevant insert, update, and retrieval operations no longer throw the reflection error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.