-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with specific values #35
Comments
@dotMorten do you have any materials where I could learn more about the bit patterns used in implementing HierarchyId? Or maybe you have some ideas how to fix this issue? |
Nope. I didn't even provide this implementation (community contribution), and honestly don't even know what it is used for. Part of me wish I didn't accept the PR, because I have a really hard time maintaining that part of the source code, and really rely on the community to do this. |
@olmobrutall Would you be able to help with this issue? Or provide some materials where I could learn more about these bits patterns?
|
Hi @ppasieka, the bit patterns come from http://www.adammil.net/blog/v100_how_the_SQL_Server_hierarchyid_data_type_works_kind_of_.html Not sure if I’ll find time to work on it, but I can review a potential change if you go for it. Cheers |
It's definitely an issue with serialization, I've converted the code to a Unit Test and also compare with values comming from the database: [DataTestMethod]
[DataRow("/1.0.2/")]
[DataRow("/1.1.2/")]
[DataRow("/1.2.2/")]
[DataRow("/1.3.2/")]
[DataRow("/3.0/")]
public void SerializeDeserialize(string route)
{
var parsed = SqlHierarchyId.Parse(route);
//var ms = new MemoryStream();
//parsed.Write(new BinaryWriter(ms));
//ms.Position = 0;
//var roundTrip = new Microsoft.SqlServer.Types.SqlHierarchyId();
//roundTrip.Read(new BinaryReader(ms));
//Assert.AreEqual(parsed, roundTrip);
using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=HierarchyTest;Integrated Security=true"))
{
con.Open();
var id = new SqlCommand($"INSERT INTO [dbo].[TreeNode] (Route) output INSERTED.ID VALUES ('{route}') ", con).ExecuteScalar();
using (var reader = new SqlCommand($"SELECT Route FROM [dbo].[TreeNode] WHERE ID = " + id, con).ExecuteReader())
{
while (reader.Read())
{
var roundTrip = new Microsoft.SqlServer.Types.SqlHierarchyId();
roundTrip.Read(new BinaryReader(reader.GetStream(0)));
Assert.AreEqual(parsed, roundTrip);
}
}
} The deserializer works, the serializer produces the error. Maybe tomorrow I can take a deeper look. |
@olmobrutall Thanks. I will also look into it tomorrow :) And yes I came to the same conclusion that the issue is with a serializer. Deserialization part work for me without any problems so far |
Fixed in #55 |
@olmobrutall amazing 👍 I will check it against my project. Thanks for that fast response 😊 |
@dotMorten Fix provided in #55 works nicely. What do you think about creating a release? With PRs #55 and #47 out, the list of HierarychId problems would be reduced to only one (#36) |
There is an issue with specific values. Using the following code in linqpad:
Using
Microsoft.SqlServer.Types.SqlHierarchyId (Microsoft.SqlServer.Types, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null)
directly in netcore31 (linqpad6) produces the same bad result.Using
Microsoft.SqlServer.Types.SqlHierarchyId (Microsoft.SqlServer.Types, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91)
directly in net46+ (linqpad5) works with all tested values as expected.(via efcore/EFCore.SqlServer.HierarchyId#7)
The text was updated successfully, but these errors were encountered: