Skip to content

Error calling AsyncUpdate against SQL Server database with identity primary keys #56

@MoxiePoxy

Description

@MoxiePoxy

The UpdateAsync method in version 2.0.1 attempts to write primary key values on update. This causes an exception on SQL Server where the primary keys are identities.

This fix is in the main branch of PetaPoco’s Database class in the ExecuteUpdate method:

// Don't update the primary key, but grab the value if we don't have it
if (string.Compare(i.Key, primaryKeyName, true) == 0)
{
    if (primaryKeyValue == null)
        primaryKeyValue = i.Value.GetValue(poco);

        continue;
}

if (primaryKeyValue == null && primaryKeyValuePairs.ContainsKey(i.Key)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions