-
Notifications
You must be signed in to change notification settings - Fork 226
HierarchyId
Simon Hughes edited this page Sep 10, 2026
·
20 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.
- Home
- Compared with the Microsoft scaffolder
- Connection strings
- JetBrains Rider
- Upgrading from v3 to v4
- Saving .tt does nothing
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets