Synchronization code

This commit is contained in:
sunkaixuan
2024-08-06 10:33:57 +08:00
parent eb3d6aefe9
commit 36285f44fa
5 changed files with 64 additions and 6 deletions

View File

@@ -695,10 +695,22 @@ namespace SqlSugar
public virtual Task<DataSet> GetDataSetAllAsync(string sql, params SugarParameter[] parameters) public virtual Task<DataSet> GetDataSetAllAsync(string sql, params SugarParameter[] parameters)
{ {
Async(); Async();
//False asynchrony . No Support DataSet //False asynchrony . No Support DataSet
return Task.Run(() => { if (CancellationToken == null)
return GetDataSetAll(sql, parameters); {
}); return Task.Run(() =>
{
return GetDataSetAll(sql, parameters);
});
}
else
{
return Task.Run(() =>
{
return GetDataSetAll(sql, parameters);
},this.CancellationToken.Value);
}
} }
#endregion #endregion

View File

@@ -330,7 +330,7 @@ namespace SqlSugar
{ {
get get
{ {
return new List<string>() { "int32", "datetime", "decimal", "double", "byte" }; return new List<string>() { "int32", "datetime", "decimal", "double", "byte", "int64", "uint32", "uint64" };
} }
} }
#endregion #endregion

View File

@@ -81,7 +81,8 @@ namespace SqlSugar
attributeType.GetProperty(nameof(SugarColumn.UpdateSql)), attributeType.GetProperty(nameof(SugarColumn.UpdateSql)),
attributeType.GetProperty(nameof(SugarColumn.ExtendedAttribute)), attributeType.GetProperty(nameof(SugarColumn.ExtendedAttribute)),
attributeType.GetProperty(nameof(SugarColumn.IsDisabledAlterColumn)), attributeType.GetProperty(nameof(SugarColumn.IsDisabledAlterColumn)),
attributeType.GetProperty(nameof(SugarColumn.IsOwnsOne)) attributeType.GetProperty(nameof(SugarColumn.IsOwnsOne)),
attributeType.GetProperty(nameof(SugarColumn.QuerySql))
} }
, new object[] { , new object[] {
sugarTable.IsPrimaryKey, sugarTable.IsPrimaryKey,
@@ -106,7 +107,8 @@ namespace SqlSugar
sugarTable.UpdateSql, sugarTable.UpdateSql,
sugarTable.ExtendedAttribute, sugarTable.ExtendedAttribute,
sugarTable.IsDisabledAlterColumn, sugarTable.IsDisabledAlterColumn,
sugarTable.IsOwnsOne sugarTable.IsOwnsOne,
sugarTable.QuerySql
}); });
return attributeBuilder; return attributeBuilder;
} }

View File

@@ -736,6 +736,7 @@ namespace SqlSugar
var addItem = readerValues[info]; var addItem = readerValues[info];
if (addItem == DBNull.Value) if (addItem == DBNull.Value)
addItem = null; addItem = null;
var underType = UtilMethods.GetUnderType(prop.PropertyType);
if (prop.PropertyType == UtilConstants.IntType) if (prop.PropertyType == UtilConstants.IntType)
{ {
addItem = addItem.ObjToInt(); addItem = addItem.ObjToInt();
@@ -752,6 +753,10 @@ namespace SqlSugar
{ {
addItem = addItem.ObjToInt(); addItem = addItem.ObjToInt();
} }
else if (addItem!=null&&underType?.FullName == "System.DateOnly")
{
addItem = Convert.ToDateTime(addItem).ToString("yyyy-MM-dd");
}
else if (UtilMethods.GetUnderType(prop.PropertyType).IsEnum() && addItem is decimal) else if (UtilMethods.GetUnderType(prop.PropertyType).IsEnum() && addItem is decimal)
{ {
if (prop.PropertyType.IsEnum() == false && addItem == null) if (prop.PropertyType.IsEnum() == false && addItem == null)

View File

@@ -950,6 +950,10 @@ namespace SqlSugar
if (value is string && type == typeof(Guid)) return new Guid(value as string); if (value is string && type == typeof(Guid)) return new Guid(value as string);
if (value is string && type == typeof(Version)) return new Version(value as string); if (value is string && type == typeof(Version)) return new Version(value as string);
if (!(value is IConvertible)) return value; if (!(value is IConvertible)) return value;
if(value is DateTime&&type.FullName== "System.DateOnly")
{
value=UtilMethods.DateTimeToDateOnly(value);
}
return Convert.ChangeType(value, type); return Convert.ChangeType(value, type);
} }
@@ -1710,6 +1714,41 @@ namespace SqlSugar
var method = value.GetType().GetMethods().First(it => it.GetParameters().Length == 0 && it.Name == "ToShortDateString"); var method = value.GetType().GetMethods().First(it => it.GetParameters().Length == 0 && it.Name == "ToShortDateString");
return method.Invoke(value, new object[] { }); return method.Invoke(value, new object[] { });
} }
internal static object DateTimeToDateOnly(object value)
{
if (value == null) return null;
// 获取DateOnly类型
Type dateOnlyType = Type.GetType("System.DateOnly, System.Runtime", throwOnError: false);
if (dateOnlyType == null)
{
throw new InvalidOperationException("DateOnly type not found.");
}
// 获取DateOnly的构造函数
var constructor = dateOnlyType.GetConstructor(new[] { typeof(int), typeof(int), typeof(int) });
if (constructor == null)
{
throw new InvalidOperationException("DateOnly constructor not found.");
}
// 使用反射调用DateTime的属性
var yearProperty = value.GetType().GetProperty("Year");
var monthProperty = value.GetType().GetProperty("Month");
var dayProperty = value.GetType().GetProperty("Day");
if (yearProperty == null || monthProperty == null || dayProperty == null)
{
throw new InvalidOperationException("DateTime properties not found.");
}
int year = (int)yearProperty.GetValue(value);
int month = (int)monthProperty.GetValue(value);
int day = (int)dayProperty.GetValue(value);
// 使用反射创建DateOnly实例
return constructor.Invoke(new object[] { year, month, day });
}
internal static void AddDiscrimator<T>(Type type, ISugarQueryable<T> queryable,string shortName=null) internal static void AddDiscrimator<T>(Type type, ISugarQueryable<T> queryable,string shortName=null)