DapperLib / DapperLib/Dapper.Contrib

InsertAsync returning 0 as Id on a class that has ExplicitKey attribute on Id

Open
#90 1 comment 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

`    public class Customer
    {
        [ExplicitKey]
        public int Id { get; set; }
        [Write(false)]
        public string FullName { get; set; }
        public string Username { get; set; }
        public string Email { get; set; }
        public string EmailToRevalidate { get; set; }
        public string SystemName { get; set; }
        public int BillingAddress_Id { get; set; }

     public int Add(Customer customer)
        {
            using (IDbConnection conn = Connection)
            {
                var result = conn.InsertAsync(customer).Result; // need to fix this it is return 0 because of the explicitkey attribue on ID.
                return result;
            }
        }

`

I need this function to return the "manually" inserted Id / Object back. Or somehow check if the insert was successful.

I believe this is somewhat buggy if it just return 0 and does not acknowledge the fact that I am using ExplicitKey attribute on Id property. Like this how am I supposed to tell if it was successful or not ?

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

Reproduce the issue with the Customer class and conn.InsertAsync(customer).Result, then trace the InsertAsync implementation and its ExplicitKey handling. Check related tests for insert return values; done means a manually supplied Id is acknowledged or a clear success result is provided, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.