I want to use SqlHierarchId in my .net project but when I try to read a SqlHierarchId from DB, System.InvalidCastException will occur. I have written a simple code which it's accessible in bellow link, to show this problem:
var connection = new SqlConnection("Data Source=.;Initial Catalog=tempdb;Integrated Security=True");
var val = connection.Query<Microsoft.SqlServer.Types.SqlHierarchyId>("select @Path", new {Path = Microsoft.SqlServer.Types.SqlHierarchyId.Parse("/1/2/3/")}).Single();
I trace code and reach the QueryImpl<T>
in SqlMappe
r class. When Dapper tries to compare the type of value which is read by SqlDataReader
, to the type of generic, confront two types of SqlHierarchyId
!