DapperLib / DapperLib/Dapper.Contrib

Insert returns 0 when using a string as an ExplicitKey on an object

Open
#69 3 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

Topic, this may also be related to DapperLib/Dapper#756 but i'm not sure if it's the same issue.
Here is the object I am using:

using Dapper.Contrib.Extensions;

[Table("CostBooks.Staff")]
public class Staff
{
    [ExplicitKey]
    public string EmplNbr { get; set; }
    public string AlphaName { get; set; }
    public bool? IsFte { get; set; }
}

Here is the method I am calling. Will try to do this with async and see what happens.

[HttpPost]
public object CreateNewStaff([FromBody]Staff s)
{
    using (IDbConnection db = DBAccessor.Connection())
    {
        if (s.EmplNbr != null)
        {
            var emplNbr = db.Insert<Staff>(s);
            return emplNbr
        }
        else
        {
            return null;
        }
    }
}

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 db.Insert(s) with the Staff model shown, especially its string [ExplicitKey] property. Inspect the insert behavior for explicit keys and determine why the call returns 0; done means the insert returns the expected result for this model and a regression test covers it.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.