DapperLib / DapperLib/Dapper.Contrib

determine the types of arguments for generic method is incorrect

Open
#49 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
293
Forks
109
PR merge metrics
No merged PRs in 30d

Description

I use Dapper.Contrib to insert my Entity, my code like this

cn.Insert(instance);

when the type of entity instance is created by emit , the generic method in Dapper.Contrib.Extensions.SqlMapperExtensions

public static long Insert<T>(this IDbConnection connection, T entityToInsert, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
{
            var isList = false;

            var type = typeof(T);

            if (type.IsArray)
            {
                isList = true;
                type = type.GetElementType();
            }
  // other codes
}

can't determine the types of entityToInsert correct, because var type = typeof(T); return typeof(object)

here is the sourcecode https://github.com/StackExchange/Dapper/blob/master/Dapper.Contrib/SqlMapperExtensions.cs#L332

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 in SqlMapperExtensions.cs around the Insert method at the referenced line and reproduce the case where an emitted entity is passed through cn.Insert(instance). Trace how the entity type is determined, then verify that inserts use the entity's actual type rather than object and add or run a regression test for the emitted entity case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.