tmsmith / Dapper-Extensions

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.
1.79k stars 586 forks source link

Unable to mapped underscore column in dapper extension #307

Open waqasahmed0323 opened 1 year ago

waqasahmed0323 commented 1 year ago

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 a 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();

hatuan commented 1 year ago

I have same problem too with predicates(Ex : var a = Predicates.Field(x => x.status_cd, Operator.Eq, "1")) Here is error : 'cd was not found for sys_status'

waqasahmed0323 commented 1 year ago

Hi @hatuan, I fixed in repo and created a pull request for approval to @valfrid-ly, waiting for approve once approved so you will get the fixed in github project.