mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Synchronization code
This commit is contained in:
@@ -64,6 +64,12 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public QueryMethodInfo AddJoinInfo(Type joinEntityType,Dictionary<string,Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expOnWhere, JoinType type = JoinType.Left)
|
||||||
|
{
|
||||||
|
var method = QueryableObj.GetType().GetMyMethod("AddJoinInfo", 4,typeof(Type), typeof(Dictionary<string, Type>), typeof(FormattableString), typeof(JoinType));
|
||||||
|
this.QueryableObj = method.Invoke(QueryableObj, new object[] { joinEntityType, keyIsShortName_ValueIsType_Dictionary, expOnWhere, type });
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public QueryMethodInfo AddJoinInfo(Type joinEntityType, string shortName, string onWhere, JoinType type = JoinType.Left)
|
public QueryMethodInfo AddJoinInfo(Type joinEntityType, string shortName, string onWhere, JoinType type = JoinType.Left)
|
||||||
{
|
{
|
||||||
var method = QueryableObj.GetType().GetMyMethod("AddJoinInfo", 4, typeof(string), typeof(string), typeof(string), typeof(JoinType));
|
var method = QueryableObj.GetType().GetMyMethod("AddJoinInfo", 4, typeof(string), typeof(string), typeof(string), typeof(JoinType));
|
||||||
@@ -88,6 +94,12 @@ namespace SqlSugar
|
|||||||
this.QueryableObj = method.Invoke(QueryableObj, new object[] { expShortName, expressionString });
|
this.QueryableObj = method.Invoke(QueryableObj, new object[] { expShortName, expressionString });
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public QueryMethodInfo Where(Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expressionString)
|
||||||
|
{
|
||||||
|
var method = QueryableObj.GetType().GetMyMethod("Where", 2, typeof(Dictionary<string, Type>), typeof(FormattableString));
|
||||||
|
this.QueryableObj = method.Invoke(QueryableObj, new object[] { keyIsShortName_ValueIsType_Dictionary, expressionString });
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public QueryMethodInfo Where(List<IConditionalModel> conditionalModels)
|
public QueryMethodInfo Where(List<IConditionalModel> conditionalModels)
|
||||||
{
|
{
|
||||||
var method = QueryableObj.GetType().GetMyMethod("Where", 1, typeof(List<IConditionalModel>));
|
var method = QueryableObj.GetType().GetMyMethod("Where", 1, typeof(List<IConditionalModel>));
|
||||||
@@ -158,6 +170,13 @@ namespace SqlSugar
|
|||||||
this.QueryableObj = method.Invoke(QueryableObj, new object[] { expShortName, expSelect, resultType });
|
this.QueryableObj = method.Invoke(QueryableObj, new object[] { expShortName, expSelect, resultType });
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public QueryMethodInfo Select(Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expSelect, Type resultType)
|
||||||
|
{
|
||||||
|
var method = QueryableObj.GetType().GetMyMethod("Select", 3, typeof(Dictionary<string, Type>), typeof(FormattableString), typeof(Type));
|
||||||
|
method = method.MakeGenericMethod(resultType);
|
||||||
|
this.QueryableObj = method.Invoke(QueryableObj, new object[] { keyIsShortName_ValueIsType_Dictionary, expSelect, resultType });
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public QueryMethodInfo Select(string selectorSql)
|
public QueryMethodInfo Select(string selectorSql)
|
||||||
{
|
{
|
||||||
var method = QueryableObj.GetType().GetMyMethod("Select", 1, typeof(string))
|
var method = QueryableObj.GetType().GetMyMethod("Select", 1, typeof(string))
|
||||||
|
@@ -580,6 +580,13 @@ namespace SqlSugar
|
|||||||
QueryBuilder.Parameters.Add(parameter);
|
QueryBuilder.Parameters.Add(parameter);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public ISugarQueryable<T> AddJoinInfo(Type JoinType, Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString onExpString, JoinType type = JoinType.Left)
|
||||||
|
{
|
||||||
|
var whereExp = DynamicCoreHelper.GetWhere(keyIsShortName_ValueIsType_Dictionary,onExpString);
|
||||||
|
var name=whereExp.Parameters.Last(it => it.Type == JoinType).Name;
|
||||||
|
var sql = this.QueryBuilder.GetExpressionValue(whereExp, ResolveExpressType.WhereMultiple).GetResultString();
|
||||||
|
return AddJoinInfo(JoinType, name, sql,type);
|
||||||
|
}
|
||||||
public ISugarQueryable<T> AddJoinInfo(Type JoinType, string shortName, string joinWhere, JoinType type = JoinType.Left)
|
public ISugarQueryable<T> AddJoinInfo(Type JoinType, string shortName, string joinWhere, JoinType type = JoinType.Left)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo(JoinType);
|
this.Context.InitMappingInfo(JoinType);
|
||||||
@@ -926,6 +933,12 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public ISugarQueryable<T> Where(Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expressionString)
|
||||||
|
{
|
||||||
|
var exp = DynamicCoreHelper.GetWhere(keyIsShortName_ValueIsType_Dictionary, expressionString);
|
||||||
|
_Where(exp);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public virtual ISugarQueryable<T> Where(string expShortName, FormattableString expressionString)
|
public virtual ISugarQueryable<T> Where(string expShortName, FormattableString expressionString)
|
||||||
{
|
{
|
||||||
var exp = DynamicCoreHelper.GetWhere<T>(expShortName, expressionString);
|
var exp = DynamicCoreHelper.GetWhere<T>(expShortName, expressionString);
|
||||||
@@ -1348,6 +1361,11 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return _Select<TResult>(expression);
|
return _Select<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
public ISugarQueryable<TResult> Select<TResult>(Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expSelect, Type resultType)
|
||||||
|
{
|
||||||
|
var exp = DynamicCoreHelper.GetMember(keyIsShortName_ValueIsType_Dictionary, resultType, expSelect);
|
||||||
|
return _Select<TResult>(exp);
|
||||||
|
}
|
||||||
public ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type resultType)
|
public ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type resultType)
|
||||||
{
|
{
|
||||||
var exp = DynamicCoreHelper.GetMember(typeof(TResult), resultType, expShortName, expSelect);
|
var exp = DynamicCoreHelper.GetMember(typeof(TResult), resultType, expShortName, expSelect);
|
||||||
|
@@ -63,8 +63,8 @@ namespace SqlSugar
|
|||||||
ISugarQueryable<T> AddParameters(SugarParameter[] parameters);
|
ISugarQueryable<T> AddParameters(SugarParameter[] parameters);
|
||||||
ISugarQueryable<T> AddParameters(List<SugarParameter> parameters);
|
ISugarQueryable<T> AddParameters(List<SugarParameter> parameters);
|
||||||
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left);
|
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left);
|
||||||
ISugarQueryable<T> AddJoinInfo(Type JoinType, string shortName, string joinWhere, JoinType type = JoinType.Left);
|
ISugarQueryable<T> AddJoinInfo(Type JoinEntityType, string shortName, string joinWhere, JoinType type = JoinType.Left);
|
||||||
|
ISugarQueryable<T> AddJoinInfo(Type JoinEntityType, Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString onExpString, JoinType type = JoinType.Left);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// if a property that is not empty is a condition
|
/// if a property that is not empty is a condition
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -86,6 +86,7 @@ namespace SqlSugar
|
|||||||
ISugarQueryable<T> TranLock(DbLockType? LockType = DbLockType.Wait);
|
ISugarQueryable<T> TranLock(DbLockType? LockType = DbLockType.Wait);
|
||||||
ISugarQueryable<T> Where(Expression<Func<T, bool>> expression);
|
ISugarQueryable<T> Where(Expression<Func<T, bool>> expression);
|
||||||
ISugarQueryable<T> Where(string expShortName, FormattableString expressionString);
|
ISugarQueryable<T> Where(string expShortName, FormattableString expressionString);
|
||||||
|
ISugarQueryable<T> Where(Dictionary<string,Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expressionString);
|
||||||
ISugarQueryable<T> Where(string whereString, object parameters = null);
|
ISugarQueryable<T> Where(string whereString, object parameters = null);
|
||||||
ISugarQueryable<T> Where(IFuncModel funcModel);
|
ISugarQueryable<T> Where(IFuncModel funcModel);
|
||||||
ISugarQueryable<T> Where(List<IConditionalModel> conditionalModels);
|
ISugarQueryable<T> Where(List<IConditionalModel> conditionalModels);
|
||||||
@@ -152,6 +153,7 @@ namespace SqlSugar
|
|||||||
bool Any();
|
bool Any();
|
||||||
Task<bool> AnyAsync();
|
Task<bool> AnyAsync();
|
||||||
ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type resultType);
|
ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type resultType);
|
||||||
|
ISugarQueryable<TResult> Select<TResult>(Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expSelect, Type resultType);
|
||||||
ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect,Type EntityType, Type resultType);
|
ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect,Type EntityType, Type resultType);
|
||||||
ISugarQueryable<T> Select(string expShortName, FormattableString expSelect, Type resultType);
|
ISugarQueryable<T> Select(string expShortName, FormattableString expSelect, Type resultType);
|
||||||
ISugarQueryable<TResult> Select<TResult>(Expression expression);
|
ISugarQueryable<TResult> Select<TResult>(Expression expression);
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -32,6 +33,46 @@ namespace SqlSugar
|
|||||||
|
|
||||||
return lambda;
|
return lambda;
|
||||||
}
|
}
|
||||||
|
public static LambdaExpression GetWhere(Dictionary<string, Type> parameterDictionary, FormattableString whereSql)
|
||||||
|
{
|
||||||
|
var parameters = parameterDictionary.Select(it => Expression.Parameter(it.Value, it.Key)).ToArray();
|
||||||
|
|
||||||
|
// 提取 FormattableString 中的参数值
|
||||||
|
var arguments = whereSql.GetArguments();
|
||||||
|
|
||||||
|
|
||||||
|
var sql = ReplaceFormatParameters(whereSql.Format);
|
||||||
|
|
||||||
|
// 构建动态表达式,使用常量表达式和 whereSql 中的参数值
|
||||||
|
var lambda = SqlSugarDynamicExpressionParser.ParseLambda(
|
||||||
|
parameters,
|
||||||
|
typeof(bool),
|
||||||
|
sql,
|
||||||
|
whereSql.GetArguments()
|
||||||
|
);
|
||||||
|
|
||||||
|
return lambda;
|
||||||
|
}
|
||||||
|
public static LambdaExpression GetMember(Dictionary<string,Type> parameterDictionary, Type propertyType, FormattableString memberSql)
|
||||||
|
{
|
||||||
|
var parameters = parameterDictionary.Select(it=> Expression.Parameter(it.Value,it.Key)).ToArray();
|
||||||
|
|
||||||
|
// 提取 FormattableString 中的参数值
|
||||||
|
var arguments = memberSql.GetArguments();
|
||||||
|
|
||||||
|
|
||||||
|
var sql = ReplaceFormatParameters(memberSql.Format);
|
||||||
|
|
||||||
|
// 构建动态表达式,使用常量表达式和 whereSql 中的参数值
|
||||||
|
var lambda = SqlSugarDynamicExpressionParser.ParseLambda(
|
||||||
|
parameters,
|
||||||
|
propertyType,
|
||||||
|
sql,
|
||||||
|
memberSql.GetArguments()
|
||||||
|
);
|
||||||
|
|
||||||
|
return lambda;
|
||||||
|
}
|
||||||
public static LambdaExpression GetMember(Type entityType,Type propertyType, string shortName, FormattableString memberSql)
|
public static LambdaExpression GetMember(Type entityType,Type propertyType, string shortName, FormattableString memberSql)
|
||||||
{
|
{
|
||||||
var parameter = Expression.Parameter(entityType, "it");
|
var parameter = Expression.Parameter(entityType, "it");
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class DynamicParameters
|
||||||
|
{
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3, string parameterName4, Type parameterType4)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 }, { parameterName4, parameterType4 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3, string parameterName4, Type parameterType4, string parameterName5, Type parameterType5)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 }, { parameterName4, parameterType4 }, { parameterName5, parameterType5 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3, string parameterName4, Type parameterType4, string parameterName5, Type parameterType5, string parameterName6, Type parameterType6)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 }, { parameterName4, parameterType4 }, { parameterName5, parameterType5 }, { parameterName6, parameterType6 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3, string parameterName4, Type parameterType4, string parameterName5, Type parameterType5, string parameterName6, Type parameterType6, string parameterName7, Type parameterType7)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 }, { parameterName4, parameterType4 }, { parameterName5, parameterType5 }, { parameterName6, parameterType6 }, { parameterName7, parameterType7 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3, string parameterName4, Type parameterType4, string parameterName5, Type parameterType5, string parameterName6, Type parameterType6, string parameterName7, Type parameterType7, string parameterName8, Type parameterType8)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 }, { parameterName4, parameterType4 }, { parameterName5, parameterType5 }, { parameterName6, parameterType6 }, { parameterName7, parameterType7 }, { parameterName8, parameterType8 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3, string parameterName4, Type parameterType4, string parameterName5, Type parameterType5, string parameterName6, Type parameterType6, string parameterName7, Type parameterType7, string parameterName8, Type parameterType8, string parameterName9, Type parameterType9)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 }, { parameterName4, parameterType4 }, { parameterName5, parameterType5 }, { parameterName6, parameterType6 }, { parameterName7, parameterType7 }, { parameterName8, parameterType8 }, { parameterName9, parameterType9 } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, Type> Create(string parameterName, Type parameterType1, string parameterName2, Type parameterType2, string parameterName3, Type parameterType3, string parameterName4, Type parameterType4, string parameterName5, Type parameterType5, string parameterName6, Type parameterType6, string parameterName7, Type parameterType7, string parameterName8, Type parameterType8, string parameterName9, Type parameterType9, string parameterName10, Type parameterType10)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Type>() { { parameterName, parameterType1 }, { parameterName2, parameterType2 }, { parameterName3, parameterType3 }, { parameterName4, parameterType4 }, { parameterName5, parameterType5 }, { parameterName6, parameterType6 }, { parameterName7, parameterType7 }, { parameterName8, parameterType8 }, { parameterName9, parameterType9 }, { parameterName10, parameterType10 } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -193,6 +193,7 @@
|
|||||||
<Compile Include="Interface\ICustomConditionalFunc.cs" />
|
<Compile Include="Interface\ICustomConditionalFunc.cs" />
|
||||||
<Compile Include="Interface\ISugarDataConverter.cs" />
|
<Compile Include="Interface\ISugarDataConverter.cs" />
|
||||||
<Compile Include="Json2Sql\DynamicLinq\DynamicCoreHelper.cs" />
|
<Compile Include="Json2Sql\DynamicLinq\DynamicCoreHelper.cs" />
|
||||||
|
<Compile Include="Json2Sql\DynamicLinq\DynamicParameters.cs" />
|
||||||
<Compile Include="Json2Sql\DynamicLinq\SqlSugarDynamicExpressionParser.cs" />
|
<Compile Include="Json2Sql\DynamicLinq\SqlSugarDynamicExpressionParser.cs" />
|
||||||
<Compile Include="Json2Sql\Entities\JsonDeleteResult.cs" />
|
<Compile Include="Json2Sql\Entities\JsonDeleteResult.cs" />
|
||||||
<Compile Include="Json2Sql\Entities\JsonInsertResult.cs" />
|
<Compile Include="Json2Sql\Entities\JsonInsertResult.cs" />
|
||||||
|
Reference in New Issue
Block a user