Skip to content

Conversation

joatansampaio
Copy link

Currently, Snapshot exposes Changes() and UpdatedColumns(), but there’s no direct way to check if any changes exist without calling Changes().Count > 0 or Changes().Any().

  • This PR adds a convenience method HasChanges() with an early-exit loop to Snapshot that improves code readability and avoids unnecessary allocation of a List when only a boolean check is needed.

Example

Before:

if (snapshot.Changes().Count > 0) // Or .Changes().Any()
{
    db.Update(obj, snapshot.UpdatedColumns());
}

After:

if (snapshot.HasChanges())
{
    db.Update(obj, snapshot.UpdatedColumns());
}

#Tests
Added unit tests in SnapshotTests verifying:

  • HasChanges returns false when no changes are made.
  • HasChanges returns true when tracked object values are updated.
  • HasChanges reutrns the same as Changes().Any()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant