Dapper.Contrib icon indicating copy to clipboard operation
Dapper.Contrib copied to clipboard

writing non-primary key id field

Open mrtristan opened this issue 6 years ago • 0 comments

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?

mrtristan avatar Feb 06 '19 16:02 mrtristan