diff --git a/Src/Asp.Net/SqlServerTest/Models/TestTree.cs b/Src/Asp.Net/SqlServerTest/Models/TestTree.cs new file mode 100644 index 000000000..359ae62a9 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/Models/TestTree.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class TestTree + { + [SqlSugar.SugarColumn(ColumnDataType = "hierarchyid")] + public string TreeId { get; set; } + public string Name { get; set; } + } +} diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 9a18c1f8a..e3a53f90e 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -87,6 +87,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs index b314b621a..2badb38dd 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs @@ -16,11 +16,15 @@ namespace OrmTest var totalPage = 0; var list=Db.Queryable().ToPageList(pageindex, pagesize, ref total, ref totalPage); - Db.CodeFirst.InitTables(typeof(CarType)); - Db.Updateable() - .SetColumns(it => new CarType { State =SqlSugar.SqlFunc.IIF(it.State==true,false,true) }).Where(it=>true) - .ExecuteCommand(); + //Db.CodeFirst.InitTables(typeof(CarType)); + //Db.Updateable() + // .SetColumns(it => new CarType { State =SqlSugar.SqlFunc.IIF(it.State==true,false,true) }).Where(it=>true) + // .ExecuteCommand(); + //Db.CodeFirst.InitTables(typeof(TestTree)); + //Db.DbMaintenance.TruncateTable(); + //Db.Ado.ExecuteCommand("insert testtree values(hierarchyid::GetRoot(),'name')"); + //var list2 = Db.Queryable().ToList(); } } } diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs index 5e3064a7a..92ca3ff3d 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs @@ -151,6 +151,10 @@ namespace SqlSugar { return "long"; } + else if (dbTypeName.Contains("hierarchyid")) + { + return "object"; + } else if (dbTypeName == "int16") { return "short"; diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs index 723d92c24..0e225becd 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs @@ -26,7 +26,6 @@ namespace SqlSugar private IDataReaderEntityBuilder DynamicBuilder; private IDataRecord DataRecord; private static readonly MethodInfo isDBNullMethod = typeof(IDataRecord).GetMethod("IsDBNull", new Type[] { typeof(int) }); - private static readonly MethodInfo getValueMethod = typeof(IDataRecord).GetMethod("get_Item", new Type[] { typeof(int) }); private static readonly MethodInfo getBoolean = typeof(IDataRecord).GetMethod("GetBoolean", new Type[] { typeof(int) }); private static readonly MethodInfo getByte = typeof(IDataRecord).GetMethod("GetByte", new Type[] { typeof(int) }); private static readonly MethodInfo getDateTime = typeof(IDataRecord).GetMethod("GetDateTime", new Type[] { typeof(int) }); @@ -38,6 +37,7 @@ namespace SqlSugar private static readonly MethodInfo getInt32 = typeof(IDataRecord).GetMethod("GetInt32", new Type[] { typeof(int) }); private static readonly MethodInfo getInt64 = typeof(IDataRecord).GetMethod("GetInt64", new Type[] { typeof(int) }); private static readonly MethodInfo getString = typeof(IDataRecord).GetMethod("GetString", new Type[] { typeof(int) }); + private static readonly MethodInfo getValueMethod = typeof(IDataRecordExtensions).GetMethod("SugarGetValue"); private static readonly MethodInfo getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset"); private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate"); private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid"); diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs index a06368f19..016f0fceb 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs @@ -136,7 +136,19 @@ namespace SqlSugar var result = dr.GetInt32(i); return result; } - + public static object SugarGetValue(this IDataRecord dr, int i) + { + if (dr.IsDBNull(i)) + { + return null; + } + var result = dr.GetValue(i); + if (result.GetType().Name == "SqlHierarchyId") + { + result = result.ObjToString(); + } + return result; + } public static long? GetConvetInt64(this IDataRecord dr, int i) { if (dr.IsDBNull(i))