-
Notifications
You must be signed in to change notification settings - Fork 224
HierarchyId
Simon Hughes edited this page Mar 20, 2026
·
19 revisions
Install the NuGet package:
Install-Package Microsoft.EntityFrameworkCore.SqlServer.HierarchyId
Add .UseHierarchyId() when configuring the DbContext:
// Via DbContextOptionsBuilder
var optionsBuilder = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlServer(@"your_connection_string", x => x.UseHierarchyId());
// Via dependency injection / Startup.cs
services.AddDbContext<MyDbContext>(options =>
options.UseSqlServer(connectionString, x => x.UseHierarchyId()));Combined with NetTopologySuite spatial types:
optionsBuilder.UseSqlServer(@"...", x => x.UseNetTopologySuite().UseHierarchyId().MaxBatchSize(100));HierarchyId is natively supported in the latest EntityFramework NuGet package — no additional packages required.
Note: If you use both HierarchyId AND table-valued functions in EF 6, you need to compile
CodeFirstStoreFunctionsagainstEntityFrameworkWithHierarchyIdrather thanEntityFramework.