DapperLib / DapperLib/Dapper.Contrib

`Insert` method always returns 0 when using [ExplicitKey].

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

If your table has a user generated key you need to generate the key property with the [ExplicitKey] attribute as per the Contrib docs. Example:

public class Employee
{
    [ExplicitKey]
    public int Id { get; set; }
    public string Name { get; set; }
    // etc etc etc
}

However the Dapper.Contrib Insert method always returns 0 meaning there is no (easy) way to determine whether or not the record was written successfully. Can you change this please so that the Id is returned to indicate success or 0 is returned for failure as it does when using a system generated key.

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

Locate the Dapper.Contrib Insert entry point and inspect how it handles the ExplicitKey attribute, comparing it with the system-generated-key path. Done means a successful insert returns the explicit Id and a failed insert returns 0, with the existing behavior preserved for generated keys.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.