Sqlclient: Implement SqlHierarchyId type for .NET Core

Created on 20 Nov 2019  路  12Comments  路  Source: dotnet/SqlClient

Microsoft SQL Server has a hierarchyid data type defined since SQL Server 2008. In the .NET Framework there is a nuget to support using the SqlHierarchyId struct: Microsoft.SqlServer.Types. Unfortunately that nuget is built for the .NET Framework and not .NET Core. If you add that nuget to a .NET Core project, the following compiler warning is produced:

Warning NU1701 Package 'Microsoft.SqlServer.Types 14.0.1016.290' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

There should be an implementation of SqlHierarchyId for .NET Core.

I tried using the Microsoft.Data.SqlClient nuget, but that does not have the SqlHierarchyId defined.
My current workaround is to use the dotMarten.Microsoft.SqlServer.Types nuget.

Related issues (which I don't think cover this same problem):

Enhancement

Most helpful comment

Any update on this? It is sorely needed

All 12 comments

Thanks for filing a separate issue on this one.
We'll consider implementing it sometime in future.

Are there any news on SqlHierarchyId?

@JohnyL

This isn't in our primary targets right now. We'll get to this when we have priority support addressed and have some room.

Any update on this? It is sorely needed

Yeah, I also wait for this feature. Hope it will be implemented soon.

Any plans to implement this?

Hi guys!

Have you tried using https://www.nuget.org/packages/Microsoft.SqlServer.DACFx that now supports Microsoft.Data.SqlClient (starting from v150.4769.1) and implements SqlHierarchyId for .NET Core, .NET Framework and .NET Standard?

If you check the "Package" defined in the .NET API reference docs,, this type in Microsoft.SqlServer.Types namespace is documented from this DACFx NuGet package.

It also seems to implement SqlGeography and SqlGeometry for all .NET platforms. (as requested in #30)

@cheenamalhotra I think it is not the cross platform package, but the old NetFX one.

@cheenamalhotra I guess, if it'd be cross-platform (as ErikEJ said), you wouldn't bother mention it.

I think I missed out on internal APIs and only saw class reference.
So even though these classes are available in .NET Core, further APIs aren't. But the fact that this NuGet is actively updated, makes me think if there's a plan ahead for DACFx to support this fully in future.

Maybe the closed source DacFx team would be willing to share their plans in the open?

There are few variants of the Microsoft.SqlServer.DACFx package:

  • Microsoft.SqlServer.DACFx -> very lightweight. A lot of things are missing. After decompiling, you can find a few "Not implemented" statements
  • Microsoft.SqlServer.DACFx.x64 -> that one actually looks good, but after running it against a database with existing data we are getting a lot of InvalidOperations exceptions on SqlGeography type. The same data are working fine with classical .net framework implementation of the SqlGeography

Anyway I'm getting this:

[NU1701] Package 'Microsoft.SqlServer.DacFx.x64 150.4826.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' 
instead of the project target framework '.NETCoreApp,Version=v3.1'. 
This package may not be fully compatible with your project.

so as @ErikEJ mentioned the packages does not seem to be cross-platform

Was this page helpful?
0 / 5 - 0 ratings