Skip to content

Documentation Question - Return Primary Key value on Insert #839

Open
@mslancashire

Description

@mslancashire

Question on the documentation on Insert, before I look at if I am doing something wrong.

Does it return just Identity / Generated or also the Primary Key. So if I am inserting the data into the Primary Key column should I expect it back as well. I ask as currently I am getting null back so when I check this against the input it throws an exception as its null.

The insert works, I checked the DB, I just have code doubling checking the returned result against the input, which fails.

For example:

var itemReference = await connection.InsertAsync<Item, string>(item);

if (itemReference .Equals(item.Reference) == false)
{
    throw new InvalidOperationException($"Failed to correctly insert item reference, returned reference of '{itemReference }' instead of `{item.Reference}`.");
}

If it should I'll starting digging into what I might be doing wrong.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions