From 36285f44fa7c2e152c65c4f9ae9039ceaace8a6a Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 6 Aug 2024 10:33:57 +0800 Subject: [PATCH] Synchronization code --- .../Abstract/AdoProvider/AdoProvider.cs | 18 +++++++-- .../Abstract/DbBindProvider/DbBindProvider.cs | 2 +- .../Abstract/DynamicBuilder/Helper.cs | 6 ++- .../SqlSugar/Infrastructure/ContextMethods.cs | 5 +++ Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs | 39 +++++++++++++++++++ 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index a05c6a99b..02419eac3 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -695,10 +695,22 @@ namespace SqlSugar public virtual Task GetDataSetAllAsync(string sql, params SugarParameter[] parameters) { Async(); + //False asynchrony . No Support DataSet - return Task.Run(() => { - return GetDataSetAll(sql, parameters); - }); + if (CancellationToken == null) + { + return Task.Run(() => + { + return GetDataSetAll(sql, parameters); + }); + } + else + { + return Task.Run(() => + { + return GetDataSetAll(sql, parameters); + },this.CancellationToken.Value); + } } #endregion diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs index 90547f95b..4a349e9f1 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs @@ -330,7 +330,7 @@ namespace SqlSugar { get { - return new List() { "int32", "datetime", "decimal", "double", "byte" }; + return new List() { "int32", "datetime", "decimal", "double", "byte", "int64", "uint32", "uint64" }; } } #endregion diff --git a/Src/Asp.Net/SqlSugar/Abstract/DynamicBuilder/Helper.cs b/Src/Asp.Net/SqlSugar/Abstract/DynamicBuilder/Helper.cs index 835f18422..072c51e10 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DynamicBuilder/Helper.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DynamicBuilder/Helper.cs @@ -81,7 +81,8 @@ namespace SqlSugar attributeType.GetProperty(nameof(SugarColumn.UpdateSql)), attributeType.GetProperty(nameof(SugarColumn.ExtendedAttribute)), attributeType.GetProperty(nameof(SugarColumn.IsDisabledAlterColumn)), - attributeType.GetProperty(nameof(SugarColumn.IsOwnsOne)) + attributeType.GetProperty(nameof(SugarColumn.IsOwnsOne)), + attributeType.GetProperty(nameof(SugarColumn.QuerySql)) } , new object[] { sugarTable.IsPrimaryKey, @@ -106,7 +107,8 @@ namespace SqlSugar sugarTable.UpdateSql, sugarTable.ExtendedAttribute, sugarTable.IsDisabledAlterColumn, - sugarTable.IsOwnsOne + sugarTable.IsOwnsOne, + sugarTable.QuerySql }); return attributeBuilder; } diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs index 0ac20ecb7..7ebab26e3 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs @@ -736,6 +736,7 @@ namespace SqlSugar var addItem = readerValues[info]; if (addItem == DBNull.Value) addItem = null; + var underType = UtilMethods.GetUnderType(prop.PropertyType); if (prop.PropertyType == UtilConstants.IntType) { addItem = addItem.ObjToInt(); @@ -752,6 +753,10 @@ namespace SqlSugar { 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) { if (prop.PropertyType.IsEnum() == false && addItem == null) diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index f7057e839..91b75dc64 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -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(Version)) return new Version(value as string); if (!(value is IConvertible)) return value; + if(value is DateTime&&type.FullName== "System.DateOnly") + { + value=UtilMethods.DateTimeToDateOnly(value); + } 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"); 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(Type type, ISugarQueryable queryable,string shortName=null)