Support Offset

This commit is contained in:
sunkaixuan 2017-09-20 12:44:10 +08:00
parent 2a9866d273
commit c116a49b99
5 changed files with 59 additions and 3 deletions

View File

@ -15,7 +15,7 @@ namespace OrmTest.Models
public int Id { get; set; }
public int? SchoolId { get; set; }
public string Name { get; set; }
public DateTime? CreateTime { get; set; }
public DateTimeOffset? CreateTime { get; set; }
[SugarColumn(IsIgnore=true)]
public int TestId { get; set; }
}

View File

@ -38,6 +38,8 @@ 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 getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
private static readonly MethodInfo getConvertStringGuid = typeof(IDataRecordExtensions).GetMethod("GetConvertStringGuid");
private static readonly MethodInfo getEnum = typeof(IDataRecordExtensions).GetMethod("GetEnum");
@ -54,11 +56,14 @@ namespace SqlSugar
private static readonly MethodInfo getConvertInt32 = typeof(IDataRecordExtensions).GetMethod("GetConvertInt32");
private static readonly MethodInfo getConvertInt64 = typeof(IDataRecordExtensions).GetMethod("GetConvetInt64");
private static readonly MethodInfo getConvertEnum_Null = typeof(IDataRecordExtensions).GetMethod("GetConvertEnum_Null");
private static readonly MethodInfo getConvertdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("GetConvertdatetimeoffset");
private static readonly MethodInfo getConvertdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetConvertdatetimeoffsetDate");
private static readonly MethodInfo getOtherNull = typeof(IDataRecordExtensions).GetMethod("GetOtherNull");
private static readonly MethodInfo getOther = typeof(IDataRecordExtensions).GetMethod("GetOther");
private static readonly MethodInfo getSqliteTypeNull = typeof(IDataRecordExtensions).GetMethod("GetSqliteTypeNull");
private static readonly MethodInfo getSqliteType = typeof(IDataRecordExtensions).GetMethod("GetSqliteType");
private static readonly MethodInfo getEntity = typeof(IDataRecordExtensions).GetMethod("GetEntity", new Type[] { typeof(SqlSugarClient) });
private delegate T Load(IDataRecord dataRecord);
private Load handler;
#endregion
@ -278,6 +283,11 @@ namespace SqlSugar
if (bindProperyTypeName == "int64" || bindProperyTypeName == "long")
method = isNullableType ? getConvertInt64 : getInt64;
break;
case CSharpDataType.DateTimeOffset:
method = isNullableType ? getConvertdatetimeoffset : getdatetimeoffset;
if (bindProperyTypeName == "datetime")
method = isNullableType ? getConvertdatetimeoffsetDate : getdatetimeoffsetDate;
break;
default:
method = getValueMethod;
break;

View File

@ -132,6 +132,49 @@ namespace SqlSugar
return reval;
}
public static DateTime GetdatetimeoffsetDate(this IDataRecord dr, int i)
{
if (dr.IsDBNull(i))
{
return DateTime.MinValue;
}
var offsetValue = (DateTimeOffset)dr.GetValue(i);
var reval = offsetValue.DateTime;
return reval;
}
public static DateTime? GetConvertdatetimeoffsetDate(this IDataRecord dr, int i)
{
if (dr.IsDBNull(i))
{
return DateTime.MinValue;
}
var offsetValue = (DateTimeOffset)dr.GetValue(i);
var reval = offsetValue.DateTime;
return reval;
}
public static DateTimeOffset Getdatetimeoffset(this IDataRecord dr, int i)
{
if (dr.IsDBNull(i))
{
return default(DateTimeOffset);
}
var reval = (DateTimeOffset)dr.GetValue(i);
return reval;
}
public static DateTimeOffset? GetConvertdatetimeoffset(this IDataRecord dr, int i)
{
if (dr.IsDBNull(i))
{
return default(DateTimeOffset);
}
var reval = (DateTimeOffset)dr.GetValue(i);
return reval;
}
public static string GetConvertString(this IDataRecord dr, int i)
{
if (dr.IsDBNull(i))

View File

@ -22,6 +22,7 @@ namespace SqlSugar
@other,
@byteArray,
@float,
@time
@time,
@DateTimeOffset
}
}

View File

@ -41,7 +41,9 @@ namespace SqlSugar
new KeyValuePair<string, CSharpDataType>("uniqueidentifier",CSharpDataType.Guid),
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("image",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray)};
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("datetimeoffset", CSharpDataType.DateTimeOffset),
new KeyValuePair<string, CSharpDataType>("datetimeoffset", CSharpDataType.DateTime)};
}
}
}