Skip to content

Fix HierarchyId to support numbers outside Int32 range#2359

Merged
AndriySvyryd merged 4 commits intomainfrom
copilot/fix-hierarchyid-parsing-issue
Mar 5, 2026
Merged

Fix HierarchyId to support numbers outside Int32 range#2359
AndriySvyryd merged 4 commits intomainfrom
copilot/fix-hierarchyid-parsing-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 5, 2026

  • Change _nodes field from int[][] to long[][] in HierarchyId.cs
  • Change parsing from int.TryParse to long.TryParse in constructor
  • Update LongArrayToString helper to accept IEnumerable<long> (renamed from IntArrayToStirng)
  • Update CompareLongArrays helper to use long[] and long locals (renamed from CompareIntArrays)
  • Fix literal new[] { 1 } in GetDescendant to new[] { 1L } for long compatibility
  • Add unit tests for parsing HierarchyIds with numbers outside Int32 range
  • Rename private helpers per review feedback: IntArrayToStirngLongArrayToString, CompareIntArraysCompareLongArrays
Original prompt

This section details on the original issue you should resolve

<issue_title>HierarchyId does not parse valid ID which contains numbers outside of the range of Int32</issue_title>
<issue_description>Hello,

I am aware that the classic Entity Framework is not developed anymore and may not get any bug fixes. At least this issue would be for documentation purposes.

If you have an hierarchy ID that contains a number outside the range of an Int32 it does not parse the ID and throws an exception that it is not a valid string representation of an hierarchy ID.

A workaround would be to use smaller hierarchy IDs unfortunately the default for a path_locator in file tables of SQL Server is such an ID.

Sample

const string ID = "/239196746533516.54209197962074.2160059995/";
// works, just to prove that it is a valid ID, you need the reference to Microsoft.SqlServer.Types
// var x = Microsoft.SqlServer.Types.SqlHierarchyId.Parse(ID);
// does not work
var y = System.Data.Entity.Hierarchy.HierarchyId.Parse(ID);

Stack trace

System.ArgumentException: The input string '/239196746533516.54209197962074.2160059995/' is not a valid string representation of a HierarchyId node.
Parameter name: hierarchyId
   at System.Data.Entity.Hierarchy.HierarchyId..ctor(String hierarchyId)
   at System.Data.Entity.Hierarchy.HierarchyId.Parse(String input)

Provider and version information

EF version: 6.5.1
Database provider: System.Data.SqlClient
Target framework: .NET Framework, .NET Core
Operating system: Windows 11
IDE: Visual Studio 17.14.16
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 5, 2026 00:56
Change internal storage from int to long (Int64) to support hierarchy IDs
with numbers exceeding Int32.MaxValue, such as SQL Server file table
path_locator values like /239196746533516.54209197962074.2160059995/.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parsing issue for hierarchy IDs with numbers outside Int32 range Fix HierarchyId to support numbers outside Int32 range Mar 5, 2026
@AndriySvyryd AndriySvyryd requested a review from Copilot March 5, 2026 01:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes HierarchyId.Parse rejecting valid hierarchy IDs containing numeric segments larger than Int32.MaxValue (e.g. SQL Server FileTable path_locator defaults) by widening the internal node representation and parsing logic to long.

Changes:

  • Widened HierarchyId internal storage and comparison helpers from int to long.
  • Updated parsing to use long.TryParse for node segments.
  • Added unit tests covering parsing and comparison of large numeric segments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/UnitTests/Hierarchy/HierarchyIdUnitTests.cs Adds regression tests for large-number parsing and comparisons.
src/EntityFramework/Hierarchy/HierarchyId.cs Switches node storage/parsing/comparison to long to support large hierarchy segments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

…CompareLongArrays

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@AndriySvyryd AndriySvyryd assigned roji and unassigned AndriySvyryd and Copilot Mar 5, 2026
@AndriySvyryd AndriySvyryd marked this pull request as ready for review March 5, 2026 01:24
@roji roji assigned AndriySvyryd and unassigned roji Mar 5, 2026
@AndriySvyryd AndriySvyryd merged commit dcaf20e into main Mar 5, 2026
2 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-hierarchyid-parsing-issue branch March 5, 2026 08:28
Copilot AI added a commit that referenced this pull request Mar 5, 2026
)

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
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.

HierarchyId does not parse valid ID which contains numbers outside of the range of Int32

4 participants