diff --git a/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs index f95e7de5a..c84e84668 100644 --- a/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs +++ b/Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs @@ -13,6 +13,17 @@ namespace OrmTest if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false)) Db.DbMaintenance.DropTable("UnitCodeTest1"); Db.CodeFirst.InitTables(); + Db.CodeFirst.InitTables(); + Db.Insertable(new Unitasdfa1() { t1 = 1, t2 = 1 }).ExecuteCommand(); + var x = Db.Queryable().ToList(); + } + public class Unitasdfa1 + { + [SqlSugar.SugarColumn(ColumnDataType = "number(8,2)")] + public decimal t2 { get; set; } + + [SqlSugar.SugarColumn(ColumnDataType ="number(8,2)")] + public decimal? t1 { get; set; } } public class UnitCodeTest1 { diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs index 5a2dda3e9..da16c28f6 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs @@ -37,7 +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 getConvertValueMethod = typeof(IDataRecordExtensions).GetMethod("GetConvertValue"); + //private static readonly MethodInfo getConvertValueMethod = typeof(IDataRecordExtensions).GetMethod("GetConvertValue"); 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"); @@ -223,7 +223,7 @@ namespace SqlSugar } else if (bindPropertyType == UtilConstants.StringType&&dbTypeName?.ToLower()== "timestamp") { - method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType); ; + method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType); } else if (bindPropertyType == UtilConstants.StringType) { @@ -231,7 +231,7 @@ namespace SqlSugar } else { - method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType); + method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType); } if (method.IsVirtual) @@ -301,11 +301,11 @@ namespace SqlSugar } if (bindPropertyType == UtilConstants.DecType) { - method = getConvertValueMethod.MakeGenericMethod(bindPropertyType); + method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType); } if (bindPropertyType == UtilConstants.IntType) { - method = getConvertValueMethod.MakeGenericMethod(bindPropertyType); + method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType); } break; case CSharpDataType.Guid: @@ -337,7 +337,7 @@ namespace SqlSugar case CSharpDataType.Single: break; default: - method = getConvertValueMethod.MakeGenericMethod(bindPropertyType); + method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType); break; } if (method == null && bindPropertyType == UtilConstants.StringType) @@ -346,7 +346,7 @@ namespace SqlSugar } if (bindPropertyType == UtilConstants.ObjType) { - method = getConvertValueMethod.MakeGenericMethod(bindPropertyType); + method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType); } if (method == null) method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType); diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs index f9da07ede..cbceeb8b1 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs @@ -136,38 +136,22 @@ namespace SqlSugar var result = dr.GetInt32(i); return result; } - public static T GetConvertValue(this IDataRecord dr, int i) - { - try - { - if (dr.IsDBNull(i)) - { - return default(T); - } - var result = dr.GetValue(i); - return UtilMethods.To(result); - } - catch (Exception ex) - { - if (dr.GetFieldType(i) == UtilConstants.DateType) - { - return UtilMethods.To(dr.GetConvertDouble(i)); - } - if (dr.GetFieldType(i) == UtilConstants.GuidType) - { - var data = dr.GetString(i); - if (data.ToString() == "") - { - return UtilMethods.To(null); - } - else - { - return UtilMethods.To(Guid.Parse(data.ToString())); - } - } - throw new Exception(ex.Message); - } - } + //public static T GetConvertValue(this IDataRecord dr, int i) + //{ + // try + // { + // if (dr.IsDBNull(i)) + // { + // return default(T); + // } + // var result = dr.GetValue(i); + // return UtilMethods.To(result); + // } + // catch (Exception ex) + // { + // return OtherException(dr, i, ex); + // } + //} public static long? GetConvetInt64(this IDataRecord dr, int i) { @@ -264,19 +248,25 @@ namespace SqlSugar { return null; } - var result = dr.GetValue(i); - return UtilMethods.To(result); + return GetOther(dr,i); } public static T GetOther(this IDataReader dr, int i) { - if (dr.IsDBNull(i)) + try { - return default(T); + if (dr.IsDBNull(i)) + { + return default(T); + } + var result = dr.GetValue(i); + return UtilMethods.To(result); + } + catch (Exception ex) + { + return OtherException(dr, i, ex); } - var result = dr.GetValue(i); - return UtilMethods.To(result); } public static T GetJson(this IDataReader dr, int i) @@ -330,6 +320,28 @@ namespace SqlSugar return null; } + + private static T OtherException(IDataRecord dr, int i, Exception ex) + { + if (dr.GetFieldType(i) == UtilConstants.DateType) + { + return UtilMethods.To(dr.GetConvertDouble(i)); + } + if (dr.GetFieldType(i) == UtilConstants.GuidType) + { + var data = dr.GetString(i); + if (data.ToString() == "") + { + return UtilMethods.To(null); + } + else + { + return UtilMethods.To(Guid.Parse(data.ToString())); + } + } + throw new Exception(ex.Message); + } + #endregion } }