Support Sqlserver tree

This commit is contained in:
sunkaixuan 2019-05-23 19:25:51 +08:00
parent cca7cb0fbb
commit 529d35c8d4
6 changed files with 42 additions and 6 deletions

View File

@ -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; }
}
}

View File

@ -87,6 +87,7 @@
<Compile Include="OldTest\Demos\K_MultiClient.cs" />
<Compile Include="OldTest\Models\Brand.cs" />
<Compile Include="OldTest\BugTest\Bug1.cs" />
<Compile Include="Models\TestTree.cs" />
<Compile Include="OldTest\Models\VendorAndBrand.cs" />
<Compile Include="OldTest\Demos\F_VersionValidation.cs" />
<Compile Include="OldTest\Demos\G_Mapper.cs" />

View File

@ -16,11 +16,15 @@ namespace OrmTest
var totalPage = 0;
var list=Db.Queryable<Order>().ToPageList(pageindex, pagesize, ref total, ref totalPage);
Db.CodeFirst.InitTables(typeof(CarType));
Db.Updateable<CarType>()
.SetColumns(it => new CarType { State =SqlSugar.SqlFunc.IIF(it.State==true,false,true) }).Where(it=>true)
.ExecuteCommand();
//Db.CodeFirst.InitTables(typeof(CarType));
//Db.Updateable<CarType>()
// .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<TestTree>();
//Db.Ado.ExecuteCommand("insert testtree values(hierarchyid::GetRoot(),'name')");
//var list2 = Db.Queryable<TestTree>().ToList();
}
}
}

View File

@ -151,6 +151,10 @@ namespace SqlSugar
{
return "long";
}
else if (dbTypeName.Contains("hierarchyid"))
{
return "object";
}
else if (dbTypeName == "int16")
{
return "short";

View File

@ -26,7 +26,6 @@ namespace SqlSugar
private IDataReaderEntityBuilder<T> 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");

View File

@ -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))