From a98508f3f658c12bb7122489071a57b940402a57 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 14 Oct 2018 16:21:29 +0800 Subject: [PATCH] Update Core --- .../Abstract/DbMaintenanceProvider/Methods.cs | 2 +- .../EntityMaintenance/EntityMaintenance.cs | 1 + .../InsertableProvider/InsertableProvider.cs | 2 +- .../QueryableProvider/QueryableProvider.cs | 78 +++++++++- .../SqlBuilderProvider/QueryBuilder.cs | 16 ++ .../UpdateProvider/UpdateableProvider.cs | 94 ++++++++++-- .../SqlSugar/Entities/EntityColumnInfo.cs | 1 + .../SqlSugar/Entities/MapperCache.cs | 141 ++++++++++++++++++ .../Entities/Mapping/SugarMappingAttribute.cs | 9 ++ .../ExpressionsToSql/DbMethods/SqlFunc.cs | 2 +- .../ResolveItems/BaseResolve.cs | 3 +- .../ExpressionsToSql/Subquery/Items/SubMax.cs | 6 +- .../ExpressionsToSql/Subquery/Items/SubMin.cs | 6 +- .../ExpressionsToSql/Subquery/Items/SubSum.cs | 8 +- .../SqlSugar/Infrastructure/Mapper.cs | 109 ++++++++++++++ .../Infrastructure/SqlSugarAccessory.cs | 2 + .../SqlSugar/Interface/IQueryable.cs | 3 + .../SqlSugar/Interface/IUpdateable.cs | 1 + .../DbMaintenance/SqliteDbMaintenance.cs | 10 ++ .../SqlSugar/SqlSugarForCore.nuspec | 2 +- .../SqlSugar/Utilities/UtilExceptions.cs | 5 + .../SqlSugar/Utilities/UtilMethods.cs | 13 +- 22 files changed, 484 insertions(+), 30 deletions(-) create mode 100644 Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/MapperCache.cs create mode 100644 Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/Mapper.cs diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 5a71d5ea7..d4c198446 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -195,7 +195,7 @@ namespace SqlSugar { oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName); newTableName = this.SqlBuilder.GetTranslationTableName(newTableName); - string sql = string.Format(this.BackupTableSql, newTableName, oldTableName, maxBackupDataRows); + string sql = string.Format(this.BackupTableSql, maxBackupDataRows, newTableName, oldTableName); this.Context.Ado.ExecuteCommand(sql); return true; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs index 495e5e87c..664013689 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs @@ -158,6 +158,7 @@ namespace SqlSugar column.DecimalDigits = sugarColumn.DecimalDigits; column.OracleSequenceName = sugarColumn.OracleSequenceName; column.IsOnlyIgnoreInsert = sugarColumn.IsOnlyIgnoreInsert; + column.IsEnableUpdateVersionValidation = sugarColumn.IsEnableUpdateVersionValidation; } else { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index e8594d9b5..0d5543097 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -289,7 +289,7 @@ namespace SqlSugar Value = column.Value, DbColumnName = column.Key, PropertyName = column.Key, - PropertyType = UtilMethods.GetUnderType(column.Value.GetType()), + PropertyType = column.Value == null? DBNull.Value.GetType(): UtilMethods.GetUnderType(column.Value.GetType()), TableId = i }; if (columnInfo.PropertyType.IsEnum()) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 00a27fadc..23379cebc 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -22,6 +22,8 @@ namespace SqlSugar public ISqlBuilder SqlBuilder { get; set; } public MappingTableList OldMappingTableList { get; set; } public MappingTableList QueryableMappingTableList { get; set; } + public Action MapperAction { get; set; } + public Action> MapperActionWithCache { get; set; } public bool IsCache { get; set; } public int CacheTime { get; set; } public bool IsAs { get; set; } @@ -70,6 +72,16 @@ namespace SqlSugar return this; } + public virtual ISugarQueryable Mapper(Action mapperAction) { + this.MapperAction = mapperAction; + return this; + } + public virtual ISugarQueryable Mapper(Action> mapperAction) + { + this.MapperActionWithCache = mapperAction; + return this; + } + public virtual ISugarQueryable AddParameters(object parameters) { if (parameters != null) @@ -179,6 +191,14 @@ namespace SqlSugar Where(SqlBuilder.SqlFalse); return this; } + if (pkValues.Length == 1&& pkValues.First() is IEnumerable) { + var newValues =new List(); + foreach (var item in pkValues.First() as IEnumerable) + { + newValues.Add(item); + } + return In(newValues); + } var pks = GetPrimaryKeys().Select(it => SqlBuilder.GetTranslationTableName(it)).ToList(); Check.Exception(pks == null || pks.Count != 1, "Queryable.In(params object[] pkValues): Only one primary key"); string filed = pks.FirstOrDefault(); @@ -427,6 +447,21 @@ namespace SqlSugar { return _Select(expression); } + + public virtual ISugarQueryable Select() + { + var isJoin = this.QueryBuilder.JoinExpression!=null; + if (isJoin) + { + var selectValue = new SugarMapper(this.Context).GetSelectValue(this.QueryBuilder); + return this.Select(selectValue); + } + else + { + return this.Select(this.SqlBuilder.SqlSelectAll); + } + } + public virtual ISugarQueryable Select(string selectValue) { var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); @@ -988,7 +1023,7 @@ namespace SqlSugar { var isSingle = QueryBuilder.IsSingle(); var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var result= Min(lamResult.GetResultString()); + var result = Min(lamResult.GetResultString()); QueryBuilder.SelectValue = null; return result; } @@ -1002,7 +1037,7 @@ namespace SqlSugar { var isSingle = QueryBuilder.IsSingle(); var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var reslut= Max(lamResult.GetResultString()); + var reslut = Max(lamResult.GetResultString()); QueryBuilder.SelectValue = null; return reslut; } @@ -1010,7 +1045,7 @@ namespace SqlSugar { var isSingle = QueryBuilder.IsSingle(); var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var reslut= Sum(lamResult.GetResultString()); + var reslut = Sum(lamResult.GetResultString()); QueryBuilder.SelectValue = null; return reslut; } @@ -1081,8 +1116,42 @@ namespace SqlSugar result = GetData(sqlObj); } RestoreMapping(); + _Mapper(result); return result; } + + protected void _Mapper(List result) + { + if (this.MapperAction != null) + { + foreach (TResult item in result) + { + if (typeof(TResult) == typeof(T)) + { + this.MapperAction((T)Convert.ChangeType(item, typeof(T))); + } + else { + Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName,typeof(T).FullName); + } + } + } + if (this.MapperActionWithCache != null) + { + if (typeof(TResult) == typeof(T)) + { + var list = (List)Convert.ChangeType(result, typeof(List)); + var mapperCache = new MapperCache(list,this.Context); + foreach (T item in list) + { + this.MapperActionWithCache(item, mapperCache); + } + } + else { + Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName); + } + } + } + protected int GetCount() { var sql = string.Empty; @@ -1184,7 +1253,7 @@ namespace SqlSugar { if (result.HasValue()) { - if (UtilMethods.GetRootBaseType(entityType).HasValue() &&UtilMethods.GetRootBaseType(entityType) == UtilConstants.ModelType) + if (UtilMethods.GetRootBaseType(entityType).HasValue() && UtilMethods.GetRootBaseType(entityType) == UtilConstants.ModelType) { foreach (var item in result) { @@ -1218,6 +1287,7 @@ namespace SqlSugar asyncQueryableBuilder.OrderByValue = this.QueryBuilder.OrderByValue; asyncQueryableBuilder.IsDisabledGobalFilter = this.QueryBuilder.IsDisabledGobalFilter; asyncQueryableBuilder.PartitionByValue = this.QueryBuilder.PartitionByValue; + asyncQueryableBuilder.JoinExpression = this.QueryBuilder.JoinExpression; return asyncQueryable; } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs index daa80d20e..a38e72a4e 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; +using System.Dynamic; using System.Linq; using System.Linq.Expressions; using System.Text; @@ -41,6 +42,8 @@ namespace SqlSugar public object SelectValue { get; set; } public string SelectCacheKey { get; set; } public string EntityName { get; set; } + + public Type EntityType { get; set; } public string TableWithString { get; set; } public string GroupByValue { get; set; } @@ -49,6 +52,7 @@ namespace SqlSugar public int JoinIndex { get; set; } public bool IsDisabledGobalFilter { get; set; } public virtual List Parameters { get; set; } + public Expression JoinExpression { get; set; } public Dictionary EasyJoinInfos { get @@ -328,6 +332,17 @@ namespace SqlSugar return string.Format(temp, sql.ToString(), (pageIndex - 1) * pageSize+1, pageIndex * pageSize); } + public virtual string GetSelectByItems(List> items) + { + var array = items.Select(it => { + dynamic dynamicObj = this.Context.Utilities.DeserializeObject(this.Context.Utilities.SerializeObject(it.Value)); + var dbName =Builder.GetTranslationColumnName( (string)(dynamicObj.dbName)); + var asName = Builder.GetTranslationColumnName((string)(dynamicObj.asName)); + return string.Format("{0}.{1} AS {2}",it.Key,dbName,asName); + }); + return string.Join(",",array); + } + public virtual string ToJoinString(JoinQueryInfo joinInfo) { return string.Format( @@ -485,6 +500,7 @@ namespace SqlSugar return this.GroupByValue; } } + #endregion private string GetTableName(string entityName) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 2e14edc01..d5462a961 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -23,6 +23,7 @@ namespace SqlSugar private List IgnoreColumnNameList { get; set; } private List WhereColumnList { get; set; } private bool IsOffIdentity { get; set; } + private bool IsVersionValidation { get; set; } public MappingTableList OldMappingTableList { get; set; } public bool IsAs { get; set; } public virtual int ExecuteCommand() @@ -31,9 +32,11 @@ namespace SqlSugar AutoRemoveDataCache(); Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions"); string sql = UpdateBuilder.ToSqlString(); + ValidateVersion(); RestoreMapping(); return this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray()); } + public bool ExecuteCommandHasChange() { return this.ExecuteCommand() > 0; @@ -64,7 +67,8 @@ namespace SqlSugar IsAs = true; OldMappingTableList = this.Context.MappingTables; this.Context.MappingTables = this.Context.Utilities.TranslateCopy(this.Context.MappingTables); - if (this.Context.MappingTables.Any(it => it.EntityName == entityName)) { + if (this.Context.MappingTables.Any(it => it.EntityName == entityName)) + { this.Context.MappingTables.Add(this.Context.MappingTables.First(it => it.EntityName == entityName).DbTableName, tableName); } this.Context.MappingTables.Add(entityName, tableName); @@ -76,6 +80,12 @@ namespace SqlSugar return this; } + public IUpdateable IsEnableUpdateVersionValidation() + { + this.IsVersionValidation = true; + return this; + } + public IUpdateable IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false) { UpdateBuilder.IsOffIdentity = isOffIdentity; @@ -110,7 +120,7 @@ namespace SqlSugar { var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings; var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices; - if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService!=null&& extService.DataInfoCacheService!=null) + if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService != null && extService.DataInfoCacheService != null) { this.RemoveDataCache(); } @@ -150,12 +160,13 @@ namespace SqlSugar return this; } - public IUpdateable UpdateColumns(Expression> columns) { + public IUpdateable UpdateColumns(Expression> columns) + { var binaryExp = columns.Body as BinaryExpression; Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString()); - Check.Exception(!(binaryExp.Left is MemberExpression)&& !(binaryExp.Left is UnaryExpression), "No support {0}", columns.ToString()); + Check.Exception(!(binaryExp.Left is MemberExpression) && !(binaryExp.Left is UnaryExpression), "No support {0}", columns.ToString()); Check.Exception(ExpressionTool.IsConstExpression(binaryExp.Left as MemberExpression), "No support {0}", columns.ToString()); - var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Replace("))",") )").Replace("((", "( (").Trim().TrimStart('(').TrimEnd(')'); + var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Replace("))", ") )").Replace("((", "( (").Trim().TrimStart('(').TrimEnd(')'); string key = SqlBuilder.GetNoTranslationColumnName(expResult); UpdateBuilder.SetValues.Add(new KeyValuePair(SqlBuilder.GetTranslationColumnName(key), expResult)); this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList(); @@ -189,7 +200,7 @@ namespace SqlSugar UpdateBuilder.SetValues.Add(new KeyValuePair(SqlBuilder.GetTranslationColumnName(key), item)); } } - this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName,StringComparison.CurrentCultureIgnoreCase)|| SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName,StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList(); + this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList(); return this; } [Obsolete("Use IUpdateable IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);")] @@ -211,20 +222,22 @@ namespace SqlSugar public IUpdateable Where(string whereSql, object parameters = null) { - if (whereSql.HasValue()) { + if (whereSql.HasValue()) + { UpdateBuilder.WhereValues.Add(whereSql); } - if (parameters != null) { + if (parameters != null) + { UpdateBuilder.Parameters.AddRange(Context.Ado.GetParameters(parameters)); } return this; } - public IUpdateable Where(string fieldName,string conditionalType, object fieldValue) + public IUpdateable Where(string fieldName, string conditionalType, object fieldValue) { - var whereSql=this.SqlBuilder.GetWhere(fieldName, conditionalType,0); + var whereSql = this.SqlBuilder.GetWhere(fieldName, conditionalType, 0); this.Where(whereSql); - string parameterName = this.SqlBuilder.SqlParameterKeyWord + fieldName+ "0"; + string parameterName = this.SqlBuilder.SqlParameterKeyWord + fieldName + "0"; this.UpdateBuilder.Parameters.Add(new SugarParameter(parameterName, fieldValue)); return this; } @@ -259,7 +272,7 @@ namespace SqlSugar foreach (var item in UpdateObjs) { List updateItem = new List(); - var isDic = item is Dictionary; + var isDic = item is Dictionary; if (isDic) { SetUpdateItemByDic(i, item, updateItem); @@ -273,14 +286,14 @@ namespace SqlSugar } private void SetUpdateItemByDic(int i, T item, List updateItem) { - foreach (var column in item as Dictionary) + foreach (var column in item as Dictionary) { var columnInfo = new DbColumnInfo() { Value = column.Value, - DbColumnName =column.Key, + DbColumnName = column.Key, PropertyName = column.Key, - PropertyType = UtilMethods.GetUnderType(column.Value.GetType()), + PropertyType = column.Value == null ? DBNull.Value.GetType() : UtilMethods.GetUnderType(column.Value.GetType()), TableId = i }; if (columnInfo.PropertyType.IsEnum()) @@ -331,7 +344,8 @@ namespace SqlSugar foreach (var item in this.UpdateBuilder.DbColumnInfoList) { if (this.UpdateBuilder.Parameters == null) this.UpdateBuilder.Parameters = new List(); - if (this.UpdateBuilder.SetValues.Any(it =>this.SqlBuilder.GetNoTranslationColumnName(it.Key) == item.PropertyName)) { + if (this.UpdateBuilder.SetValues.Any(it => this.SqlBuilder.GetNoTranslationColumnName(it.Key) == item.PropertyName)) + { continue; } this.UpdateBuilder.Parameters.Add(new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType)); @@ -449,5 +463,53 @@ namespace SqlSugar asyncUpdateableBuilder.SetValues = this.UpdateBuilder.SetValues; return asyncUpdateable; } + + private void ValidateVersion() + { + var versionColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsEnableUpdateVersionValidation); + var pks = this.UpdateBuilder.DbColumnInfoList.Where(it => it.IsPrimarykey).ToList(); + if (versionColumn != null && this.IsVersionValidation) + { + Check.Exception(pks.IsNullOrEmpty(), "UpdateVersionValidation the primary key is required."); + List conModels = new List(); + foreach (var item in pks) + { + conModels.Add(new ConditionalModel() { FieldName = item.DbColumnName, ConditionalType = ConditionalType.Equal, FieldValue = item.Value.ObjToString() }); + } + var dbInfo = this.Context.Queryable().Where(conModels).First(); + if (dbInfo != null) + { + var currentVersion = this.EntityInfo.Type.GetProperty(versionColumn.PropertyName).GetValue(UpdateObjs.Last(), null); + var dbVersion = this.EntityInfo.Type.GetProperty(versionColumn.PropertyName).GetValue(dbInfo, null); + Check.Exception(currentVersion == null, "UpdateVersionValidation entity property {0} is not null", versionColumn.PropertyName); + Check.Exception(dbVersion == null, "UpdateVersionValidation database column {0} is not null", versionColumn.DbColumnName); + if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.LongType)) + { + if (Convert.ToInt64(dbVersion) > Convert.ToInt64(currentVersion)) + { + throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName)); + } + } + else if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.DateType)) + { + if (dbVersion.ObjToDate() > currentVersion.ObjToDate()) + { + throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName)); + } + } + else if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.ByteArrayType)) + { + if (UtilMethods.GetLong((byte[])dbVersion)>UtilMethods.GetLong((byte[])currentVersion)) + { + throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName)); + } + } + else + { + Check.ThrowNotSupportedException(string.Format("UpdateVersionValidation Not Supported Type [ {0} ] , {1}", versionColumn.PropertyInfo.PropertyType, versionColumn.PropertyName)); + } + } + } + } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/EntityColumnInfo.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/EntityColumnInfo.cs index 962ea2264..c35cb9dab 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/EntityColumnInfo.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/EntityColumnInfo.cs @@ -19,6 +19,7 @@ namespace SqlSugar public bool IsNullable { get; set; } public bool IsIdentity { get; set; } public bool IsPrimarykey { get; set; } + public bool IsEnableUpdateVersionValidation { get; set; } public string EntityName { get; set; } public string DbTableName { get; set; } public bool IsIgnore { get; set; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/MapperCache.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/MapperCache.cs new file mode 100644 index 000000000..083a39e8b --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/MapperCache.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SqlSugar +{ + public class MapperCache + { + private Dictionary caches = new Dictionary(); + private List _list { get; set; } + private SqlSugarClient _context { get; set; } + private MapperCache() + { + } + public MapperCache(List list, SqlSugarClient context) + { + _list = list; + _context = context; + } + public Result Get(Func, Result> action) + { + string key = "Get" + typeof(Result) + action.GetHashCode().ToString(); + if (caches.ContainsKey(key)) + { + return (Result)caches[key]; + } + else + { + var result = action(_list); + caches.Add(key, result); + return result; + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + public List GetListByPrimaryKeys(Func action) where Result : class, new() + { + { + string key = "GetListById" + typeof(Result) + action.GetHashCode().ToString(); + return GetListByPrimaryKeys(action, key); + } + } + private List GetListByPrimaryKeys(Func action, string key) where Result : class, new() + { + if (caches.ContainsKey(key)) + { + return (List)caches[key]; + } + else + { + var ids = _list.Select(action).ToList().Distinct().ToList(); + var result = _context.Queryable().In(ids).ToList(); + caches.Add(key, result); + return result; + } + } + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs index b9200945f..a44d15660 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs @@ -105,6 +105,15 @@ namespace SqlSugar get { return _IsOnlyIgnoreInsert; } set { _IsOnlyIgnoreInsert = value; } } + + + private bool _IsEnableUpdateVersionValidation; + public bool IsEnableUpdateVersionValidation { + get { return _IsEnableUpdateVersionValidation; } + set { _IsEnableUpdateVersionValidation = value; } + } + + } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs index e33cf1b69..4ea9dc4dc 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs @@ -100,7 +100,7 @@ namespace SqlSugar public static TResult AggregateAvg(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); } public static TResult AggregateMin(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); } public static TResult AggregateMax(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); } - public static int AggregateCount(int thisValue) { throw new NotSupportedException("Can only be used in expressions"); } + public static int AggregateCount(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); } public static TResult MappingColumn(TResult oldColumnName,string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); } /// ///Example: new NewT(){name=SqlFunc.GetSelfAndAutoFill(it)} Generated SQL it.* diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index 8251946c5..f4849ae58 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs @@ -256,6 +256,7 @@ namespace SqlSugar newContext.MappingColumns = this.Context.MappingColumns; newContext.MappingTables = this.Context.MappingTables; newContext.IgnoreComumnList = this.Context.IgnoreComumnList; + newContext.IsSingle = this.Context.IsSingle; newContext.SqlFuncServices = this.Context.SqlFuncServices; newContext.Resolve(item, this.Context.IsJoin ? ResolveExpressType.WhereMultiple : ResolveExpressType.WhereSingle); this.Context.Index = newContext.Index; @@ -278,7 +279,7 @@ namespace SqlSugar protected string GetNewExpressionValue(Expression item) { - var newContext = this.Context.GetCopyContext(); + var newContext = this.Context.GetCopyContextWithMapping(); newContext.Resolve(item, this.Context.IsJoin ? ResolveExpressType.WhereMultiple : ResolveExpressType.WhereSingle); this.Context.Index = newContext.Index; this.Context.ParameterIndex = newContext.ParameterIndex; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs index 59fa5c51d..137647595 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs @@ -43,7 +43,11 @@ namespace SqlSugar public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; - return "MAX("+SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle)+")"; + var argExp = exp.Arguments[0]; + var result = "MAX(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")"; + var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; + result = result.Replace(selfParameterName, string.Empty); + return result; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs index 5d51fbb3f..5636b6a20 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs @@ -43,7 +43,11 @@ namespace SqlSugar public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; - return "MIN(" + SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle) + ")"; + var argExp = exp.Arguments[0]; + var result = "MIN(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")"; + var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; + result = result.Replace(selfParameterName, string.Empty); + return result; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs index 00b212cad..cd757de22 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs @@ -6,7 +6,7 @@ using System.Text; namespace SqlSugar { - public class SubSum:ISubOperation + public class SubSum : ISubOperation { public bool HasWhere { @@ -43,7 +43,11 @@ namespace SqlSugar public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; - return "SUM("+SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle)+")"; + var argExp = exp.Arguments[0]; + var result = "SUM(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple)+")"; + var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; + result = result.Replace(selfParameterName, string.Empty); + return result; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/Mapper.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/Mapper.cs new file mode 100644 index 000000000..2de6f1526 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/Mapper.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; + +namespace SqlSugar +{ + public class SugarMapper + { + private SqlSugarClient _context; + public SugarMapper(SqlSugarClient context) + { + _context = context; + } + + public string GetSelectValue(QueryBuilder queryBuilder) + { + string result = string.Empty; + var veiwModel = _context.EntityMaintenance.GetEntityInfo(); + var exp = (queryBuilder.JoinExpression as LambdaExpression); + List> selectItems = new List>(); + foreach (var viewColumn in veiwModel.Columns) + { + var exParsmeters = exp.Parameters.Select(it => new { shortName = it.Name, type = it.Type }).ToList(); + foreach (var expPars in exParsmeters) + { + var columns = _context.EntityMaintenance.GetEntityInfo(expPars.type).Columns.Where(it => it.IsIgnore == false); + var joinModelDbColumns = columns.Select(it => + new { asName = it.PropertyName, dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + var joinModelProperties = columns.Select(it => + new { asName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + var joinModelDbColumnsWithType = columns.Select(it => + new { asName = (expPars.type.Name + it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + var joinModelPropertiesWithTye = columns.Select(it => + new { asName = (expPars.type.Name + _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + var joinModelDbColumns_WithType = columns.Select(it => + new { asName = (expPars.type.Name +"_"+ it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + var joinModelProperties_WithType = columns.Select(it => + new { asName = (expPars.type.Name +"_"+ _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + var joinModelDbColumnsWithSN = columns.Select(it => + new { asName = (expPars.shortName + it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + var joinModelPropertiesWithSN = columns.Select(it => + new { asName = (expPars.shortName + _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList(); + + if (joinModelDbColumns.Any(it => it.asName.Equals(viewColumn.PropertyName,StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelDbColumns.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName,value)); + break; + } + if (joinModelProperties.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelProperties.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName, value)); + break; + } + if (joinModelDbColumnsWithType.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelDbColumnsWithType.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName, value)); + break; + } + if (joinModelPropertiesWithTye.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelPropertiesWithTye.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName, value)); + break; + } + + if (joinModelDbColumns_WithType.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelDbColumns_WithType.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName, value)); + break; + } + if (joinModelProperties_WithType.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelProperties_WithType.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName, value)); + break; + } + if (joinModelDbColumnsWithSN.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelDbColumnsWithSN.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName, value)); + break; + } + if (joinModelPropertiesWithSN.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase))) + { + var value = joinModelPropertiesWithSN.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)); + if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase)) + selectItems.Add(new KeyValuePair(expPars.shortName, value)); + break; + } + } + } + result = queryBuilder.GetSelectByItems(selectItems); + return result; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs index d2ea61dbd..f945fbdc2 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs @@ -315,6 +315,7 @@ namespace SqlSugar List paramters = new List(); queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(queryable.SqlBuilder, joinExpression, ref paramters, ref shortName, types); queryable.SqlBuilder.QueryBuilder.TableShortName = shortName; + queryable.SqlBuilder.QueryBuilder.JoinExpression = joinExpression; if (paramters != null) { queryable.SqlBuilder.QueryBuilder.Parameters.AddRange(paramters); @@ -326,6 +327,7 @@ namespace SqlSugar string shortName = string.Empty; queryable.SqlBuilder.QueryBuilder.EasyJoinInfos = this.GetEasyJoinInfo(joinExpression, ref shortName, queryable.SqlBuilder, types); queryable.SqlBuilder.QueryBuilder.TableShortName = shortName; + queryable.SqlBuilder.QueryBuilder.JoinExpression=joinExpression; } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs index c870f2a4a..bab64f28b 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs @@ -19,6 +19,8 @@ namespace SqlSugar ISugarQueryable AS(string tableName); ISugarQueryable With(string withString); ISugarQueryable Filter(string FilterName, bool isDisabledGobalFilter = false); + ISugarQueryable Mapper(Action mapperAction); + ISugarQueryable Mapper(Action> mapperAction); ISugarQueryable AddParameters(object parameters); ISugarQueryable AddParameters(SugarParameter[] parameters); ISugarQueryable AddParameters(List parameters); @@ -74,6 +76,7 @@ namespace SqlSugar Task AnyAsync(); ISugarQueryable Select(Expression> expression); + ISugarQueryable Select(); ISugarQueryable Select(string select); ISugarQueryable Select(string select); ISugarQueryable MergeTable(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs index 8131fdd02..21dee2c27 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs @@ -41,6 +41,7 @@ namespace SqlSugar IUpdateable IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false); IUpdateable IgnoreColumns(Expression> columns); IUpdateable IgnoreColumns(Func ignoreColumMethod); + IUpdateable IsEnableUpdateVersionValidation(); IUpdateable ReSetValue(Expression> setValueExpression); IUpdateable RemoveDataCache(); KeyValuePair> ToSql(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs index 16e5875a9..5eb077890 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbMaintenance/SqliteDbMaintenance.cs @@ -242,6 +242,16 @@ namespace SqlSugar this.Context.Ado.ExecuteCommand(sql); return true; } + + public override bool BackupTable(string oldTableName, string newTableName, int maxBackupDataRows = int.MaxValue) + { + oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName); + newTableName = this.SqlBuilder.GetTranslationTableName(newTableName); + string sql = string.Format(this.BackupTableSql, newTableName, oldTableName, maxBackupDataRows); + this.Context.Ado.ExecuteCommand(sql); + return true; + } + protected override string GetCreateTableSql(string tableName, List columns) { List columnArray = new List(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec index 3ad535b14..6e0732932 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec @@ -2,7 +2,7 @@ sqlSugarCore - 4.7 + 4.8 sunkaixuan Landa http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilExceptions.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilExceptions.cs index a4597317a..f7c34d994 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilExceptions.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilExceptions.cs @@ -52,4 +52,9 @@ namespace SqlSugar return string.Format("{0} : '{1}' \r\n", key, value); } } + public class VersionExceptions : UtilExceptions + { + public VersionExceptions(string message) + : base(message){ } + } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs index 410d6dd9a..821b2b45d 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs @@ -14,7 +14,7 @@ namespace SqlSugar internal static Type GetUnderType(Type oldType) { Type type = Nullable.GetUnderlyingType(oldType); - return type==null ? oldType : type; + return type == null ? oldType : type; } internal static Type GetRootBaseType(Type entityType) @@ -103,5 +103,16 @@ namespace SqlSugar action(); return value; } + + internal static object DefaultForType(Type targetType) + { + return targetType.IsValueType ? Activator.CreateInstance(targetType) : null; + } + + internal static Int64 GetLong(byte[] bytes) + { + return Convert.ToInt64(string.Join("", bytes).PadRight(20, '0')); + } + } }