DapperLib / DapperLib/Dapper.Contrib

writing non-primary key id field

Open
#56 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

given the below simplified class:

[Table ("TableName")]
public class ClassName
{
    [ExplicitKey]
    public Guid PKId { get; set; }
    public string Id { get; set; }
}

dapper contrib's Insert seems to be skipping the Id writing completely.

and for whatever it's worth, the naming convention around this particular table is out of my control.

i just had another thought in that i tried the following and it worked:

[Table ("TableName")]
public class ClassName
{
    [Key]
    [ExplicitKey]
    public Guid PKId { get; set; }
    public string Id { get; set; }
}

however, the PKID field is indeed set by the application, not the database so having [ExplicitKey] is more appropriate

any thoughts on this behavior?

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 at the Insert entry point and reproduce the shown ClassName mapping, comparing [ExplicitKey] with the version that also has [Key]. Check whether the non-primary-key Id is omitted from the generated insert. Done means Insert writes Id while leaving the application-assigned PKId behavior intact.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.