diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs index b74f06668..3e6ce1b8c 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs @@ -833,6 +833,18 @@ namespace SqlSugar { return new SaveableProvider(this, saveObject); } + public StorageableDataTable Storageable(List> dictionaryList, string tableName) + { + DataTable dt = this.Context.Utilities.DictionaryListToDataTable(dictionaryList); + dt.TableName = tableName; + return this.Context.Storageable(dt); + } + public StorageableDataTable Storageable(Dictionary dictionary, string tableName) + { + DataTable dt = this.Context.Utilities.DictionaryListToDataTable(new List>() { dictionary }); + dt.TableName = tableName; + return this.Context.Storageable(dt); + } public IStorageable Storageable(List dataList) where T : class, new() { this.InitMappingInfo(); diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs index d1c995ee3..8231e8b32 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs @@ -566,6 +566,14 @@ namespace SqlSugar { return ScopedContext.SqlQueryable(sql); } + public StorageableDataTable Storageable(List> dictionaryList, string tableName) + { + return ScopedContext.Storageable(dictionaryList, tableName); + } + public StorageableDataTable Storageable(Dictionary dictionary, string tableName) + { + return ScopedContext.Storageable(dictionary, tableName); + } public IStorageable Storageable(List dataList) where T : class, new() { diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index bc3849c5d..ed785a058 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -681,5 +681,13 @@ namespace SqlSugar model.Args[0].MemberName = name; return AggregateSum(model); } + public virtual string JsonListObjectAny(MethodCallExpressionModel model) + { + throw new NotImplementedException("Current database no support"); + } + public virtual string JsonArrayAny(MethodCallExpressionModel model) + { + throw new NotImplementedException("Current database no support"); + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs index b2197ee4d..828972fe7 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs @@ -100,5 +100,7 @@ namespace SqlSugar string JsonLike(MethodCallExpressionModel model); string Collate(MethodCallExpressionModel model); string AggregateSumNoNull(MethodCallExpressionModel model); + string JsonListObjectAny(MethodCallExpressionModel model); + string JsonArrayAny(MethodCallExpressionModel model); } } diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs index 2c4a44e0f..6d72f0440 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs @@ -256,5 +256,15 @@ namespace SqlSugar public static DateTime Oracle_ToDate(string date,string format) { throw new NotSupportedException("Can only be used in expressions"); } public static string Oracle_ToChar(DateTime date, string format) { throw new NotSupportedException("Can only be used in expressions"); } public static int SqlServer_DateDiff(string dateType,DateTime date1,DateTime date2) { throw new NotSupportedException("Can only be used in expressions"); } + + public static bool JsonListObjectAny(object jsonListObject, string fieldName, object value) + { + throw new NotSupportedException("Can only be used in expressions"); + } + + public static bool JsonArrayAny(object jsonArray,object arrayValue) + { + throw new NotSupportedException("Can only be used in expressions"); + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs index 044016e65..ddf54097a 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs @@ -752,6 +752,10 @@ namespace SqlSugar return this.Context.DbMehtods.Collate(model); case "AggregateSumNoNull": return this.Context.DbMehtods.AggregateSumNoNull(model); + case "JsonListObjectAny": + return this.Context.DbMehtods.JsonListObjectAny(model); + case "JsonArrayAny": + return this.Context.DbMehtods.JsonArrayAny(model); default: break; } diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs b/Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs index 4022cc367..0cd98a8e3 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs @@ -137,6 +137,8 @@ namespace SqlSugar #endregion #region Saveable + StorageableDataTable Storageable(List> dictionaryList, string tableName); + StorageableDataTable Storageable(Dictionary dictionary, string tableName); IStorageable Storageable(List dataList) where T : class, new(); IStorageable Storageable(T data) where T : class, new(); StorageableDataTable Storageable(DataTable data); diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs index 94db64913..336d7d0ae 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs @@ -217,5 +217,28 @@ namespace SqlSugar { return $"{memberName1}->\"$.{memberName2}\""; } + + public override string JsonArrayAny(MethodCallExpressionModel model) + { + if (UtilMethods.IsNumber(model.Args[1].MemberValue.GetType().Name)) + { + return $"JSON_CONTAINS({model.Args[0].MemberName}, '{model.Args[1].MemberValue}')"; + } + else + { + return $"JSON_CONTAINS({model.Args[0].MemberName}, '\"{model.Args[1].MemberValue.ObjToStringNoTrim().ToSqlFilter()}\"')"; + } + } + public override string JsonListObjectAny(MethodCallExpressionModel model) + { + if (UtilMethods.IsNumber(model.Args[2].MemberValue.GetType().Name)) + { + return $"JSON_CONTAINS({model.Args[0].MemberName},'{{\"{model.Args[1].MemberValue}\":{model.Args[2].MemberValue}}}')"; + } + else + { + return $"JSON_CONTAINS({model.Args[0].MemberName},'{{\"{model.Args[1].MemberValue}\":\"{model.Args[2].MemberValue.ObjToStringNoTrim().ToSqlFilter()}\"}}')"; + } + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs index b073f09bf..cebea6248 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs @@ -443,5 +443,28 @@ namespace SqlSugar //var parameter1 = model.Args[1]; return $" ({parameter.MemberName}::json) "; } + + public override string JsonArrayAny(MethodCallExpressionModel model) + { + if (UtilMethods.IsNumber(model.Args[1].MemberValue.GetType().Name)) + { + return $"{model.Args[0].MemberName}::jsonb @> '[{model.Args[1].MemberValue.ObjToStringNoTrim().ToSqlFilter()}]'::jsonb"; + } + else + { + return $"{model.Args[0].MemberName}::jsonb @> '[\"{model.Args[1].MemberValue}\"]'::jsonb"; + } + } + public override string JsonListObjectAny(MethodCallExpressionModel model) + { + if (UtilMethods.IsNumber(model.Args[2].MemberValue.GetType().Name)) + { + return $"{model.Args[0].MemberName}::jsonb @> '[{{\"{model.Args[1].MemberValue}\":{model.Args[2].MemberValue}}}]'::jsonb"; + } + else + { + return $"{model.Args[0].MemberName}::jsonb @> '[{{\"{model.Args[1].MemberValue}\":\"{model.Args[2].MemberValue.ObjToStringNoTrim().ToSqlFilter()}\"}}]'::jsonb"; + } + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs b/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs index f46242b47..409668d97 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs @@ -569,7 +569,14 @@ namespace SqlSugar { return ScopedContext.SqlQueryable(sql); } - + public StorageableDataTable Storageable(List> dictionaryList, string tableName) + { + return ScopedContext.Storageable(dictionaryList, tableName); + } + public StorageableDataTable Storageable(Dictionary dictionary, string tableName) + { + return ScopedContext.Storageable(dictionary, tableName); + } public IStorageable Storageable(List dataList) where T : class, new() { return ScopedContext.Storageable(dataList);