Fix SequentialSqlGuid in-memory sorting#20
Merged
buvinghausen merged 3 commits intomasterfrom Mar 21, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes SequentialSqlGuid’s in-memory comparison semantics so sorting matches SQL Server uniqueidentifier ordering by delegating comparisons (and related equality/hash behavior) to System.Data.SqlTypes.SqlGuid. It also adds/adjusts tests to ensure sort-order regressions are caught explicitly.
Changes:
- Update
SequentialSqlGuid.CompareTo(SequentialSqlGuid),Equals, andGetHashCodeto useSqlGuidfor SQL Server–compatible semantics. - Expand
CompareTo(object)to acceptSqlGuiddirectly. - Add/adjust tests in v7/v8 and core test suites to verify ordering with
ignoreOrder: falseand to validate timestamp extraction for known vectors.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/SequentialGuid/SequentialSqlGuid.cs |
Routes comparison/equality/hash behavior through SqlGuid to align with SQL Server ordering. |
test/SequentialGuid.Tests/SequentialGuidTests.cs |
Makes ordering assertions explicit (ignoreOrder: false) and standardizes sorted-list types. |
test/SequentialGuid.Tests/GuidV7Tests.cs |
Adds explicit sorted-list order verification for SequentialGuid and SequentialSqlGuid v7 vectors. |
test/SequentialGuid.Tests/GuidV8TimeTests.cs |
Adds explicit sorted-list order verification for SequentialGuid and SequentialSqlGuid v8 time vectors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
SequentialSqlGuidin-memory sortingProblem
SequentialSqlGuid.CompareTowas delegating toGuid.CompareTo, which uses standard byte-order comparison. SQL Server sortsuniqueidentifiervalues using a different byte-order priority, so in-memory sorting ofSequentialSqlGuiddid not match the order SQL Server would produce.Fix
SequentialSqlGuidnow wraps calls throughSystem.Data.SqlTypes.SqlGuidto ensureCompareTo,Equals, andGetHashCodeall use SQL Server–compatible byte ordering:The
CompareTo(object)overload also now acceptsSqlGuiddirectly.Tests
SortedGuidList/SortedSqlGuidListsort-order verification tests to bothGuidV7TestsandGuidV8TimeTests, confirming thatSequentialGuidandSequentialSqlGuidcollections sort in the expected byte order with version/variant bits and a known timestamp.ShouldBeassertions to useignoreOrder: falseso sort-order regressions are caught explicitly.IList<T>tostatic IReadOnlyList<T>inSequentialGuidTestsfor consistency.