You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enhanced Client-Side Support for LTree Type (Similar to Microsoft.EntityFrameworkCore.SqlServer.HierarchyId) #3610
First, thank you for your excellent work on the Npgsql.EntityFrameworkCore.PostgreSQL provider!
I'm writing to propose the development of an enhanced library for the LTree type that provides full client-side operation capabilities, aiming to achieve feature parity and a similar developer experience with Microsoft.EntityFrameworkCore.SqlServer.HierarchyId.
Reasoning:
Currently, the LTree type is primarily a thin wrapper around string, with all logical operations executed on the database server. This requires developers to use LINQ queries for even simple operations, making client-side manipulation and inspection of hierarchical data cumbersome. Many operations that are natural in C# code throw exceptions.
An enhanced LTree type with client-side capabilities would significantly improve developer productivity and flexibility when working with hierarchical data in PostgreSQL. It would make the choice between PostgreSQL's ltree and SQL Server's HierarchyId less influenced by differences in client-side development experience.
Desired Enhancements:
Client-Side API: A rich set of methods (e.g., GetLevel(), IsDescendantOf(), GetAncestor(), GetDescendant(), GetReparentedValue()) that can execute entirely in memory without requiring database round-trips.5
LINQ Translation: Maintain and potentially extend the existing excellent LINQ translation for server-side queries for these new methods.
Extended Functionality: Incorporate more advanced hierarchical operations currently available in HierarchyId.5
Optional Package: This enhanced functionality could be provided in a separate optional NuGet package (e.g., Npgsql.EntityFrameworkCore.PostgreSQL.LTree) to keep the core provider lightweight.
Considerations:
I understand that this would increase maintenance overhead and require careful design to avoid naming conflicts and performance pitfalls. Clear documentation on the intended use cases (client-side vs. server-side operations) would be crucial.
Thank you for considering this proposal. I believe this would be a valuable addition for developers leveraging PostgreSQL's powerful ltree module.
changed the title [-]Enhanced Client-Side Support for LTree Type (Similar to SQL Server's HierarchyId[/-][+]Enhanced Client-Side Support for LTree Type (Similar to Microsoft.EntityFrameworkCore.SqlServer.HierarchyId)[/+]on Sep 2, 2025
Can you provide more context on why you think client-side operations on LTree is something that developers need?
ltree is a PostgreSQL type, and the EFCore.PG support is intended to allow users to use that (server-side) support. It's definitely not the intent here to provide a general .NET hierarchical data API that could be used without the database - that's out of scope for an EF provider/database driver. As you noted, this would add a non-trivial maintenance burden on the provider which I don't think makes sense.
There are various other such examples, where a database-side capability is merely exposed, without any attempt to provide client-side implementations. For example, it obviously makes no sense to attempt to provide a client-side implementation of full-text search; ltree is slightly different but I believe the general principle still applies.
BTW in any case, if we were to do something like this, it would belong at the lower-level Npgsql layer rather than in the EF provider layer.
You're absolutely right. I agree that keeping the focus on the database-side implementation is the correct approach for the EF provider. Thanks for explaining the scope and maintenance considerations.
Activity
[-]Enhanced Client-Side Support for LTree Type (Similar to SQL Server's HierarchyId[/-][+]Enhanced Client-Side Support for LTree Type (Similar to Microsoft.EntityFrameworkCore.SqlServer.HierarchyId)[/+]roji commentedon Sep 2, 2025
Can you provide more context on why you think client-side operations on LTree is something that developers need?
ltree is a PostgreSQL type, and the EFCore.PG support is intended to allow users to use that (server-side) support. It's definitely not the intent here to provide a general .NET hierarchical data API that could be used without the database - that's out of scope for an EF provider/database driver. As you noted, this would add a non-trivial maintenance burden on the provider which I don't think makes sense.
There are various other such examples, where a database-side capability is merely exposed, without any attempt to provide client-side implementations. For example, it obviously makes no sense to attempt to provide a client-side implementation of full-text search; ltree is slightly different but I believe the general principle still applies.
BTW in any case, if we were to do something like this, it would belong at the lower-level Npgsql layer rather than in the EF provider layer.
gimmickj commentedon Sep 2, 2025
You're absolutely right. I agree that keeping the focus on the database-side implementation is the correct approach for the EF provider. Thanks for explaining the scope and maintenance considerations.