mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update Core
This commit is contained in:
parent
60b5e61e03
commit
6cf8b1d3ee
@ -226,6 +226,8 @@ namespace SqlSugar
|
|||||||
|
|
||||||
#region Core
|
#region Core
|
||||||
public virtual int ExecuteCommand(string sql, params SugarParameter[] parameters)
|
public virtual int ExecuteCommand(string sql, params SugarParameter[] parameters)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (this.ProcessingEventStartingSQL != null)
|
if (this.ProcessingEventStartingSQL != null)
|
||||||
ExecuteProcessingSQL(ref sql, parameters);
|
ExecuteProcessingSQL(ref sql, parameters);
|
||||||
@ -235,9 +237,17 @@ namespace SqlSugar
|
|||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close();
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (this.IsClose()) this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters)
|
public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters)
|
||||||
{
|
{
|
||||||
var isSp = this.CommandType == CommandType.StoredProcedure;
|
var isSp = this.CommandType == CommandType.StoredProcedure;
|
||||||
@ -245,8 +255,7 @@ namespace SqlSugar
|
|||||||
ExecuteProcessingSQL(ref sql, parameters);
|
ExecuteProcessingSQL(ref sql, parameters);
|
||||||
ExecuteBefore(sql, parameters);
|
ExecuteBefore(sql, parameters);
|
||||||
IDbCommand sqlCommand = GetCommand(sql, parameters);
|
IDbCommand sqlCommand = GetCommand(sql, parameters);
|
||||||
var isAutoClose = this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null;
|
IDataReader sqlDataReader = sqlCommand.ExecuteReader(this.IsClose() ? CommandBehavior.CloseConnection : CommandBehavior.Default);
|
||||||
IDataReader sqlDataReader = sqlCommand.ExecuteReader(isAutoClose ? CommandBehavior.CloseConnection : CommandBehavior.Default);
|
|
||||||
if (isSp)
|
if (isSp)
|
||||||
DataReaderParameters = sqlCommand.Parameters;
|
DataReaderParameters = sqlCommand.Parameters;
|
||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
@ -255,6 +264,8 @@ namespace SqlSugar
|
|||||||
return sqlDataReader;
|
return sqlDataReader;
|
||||||
}
|
}
|
||||||
public virtual DataSet GetDataSetAll(string sql, params SugarParameter[] parameters)
|
public virtual DataSet GetDataSetAll(string sql, params SugarParameter[] parameters)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (this.ProcessingEventStartingSQL != null)
|
if (this.ProcessingEventStartingSQL != null)
|
||||||
ExecuteProcessingSQL(ref sql, parameters);
|
ExecuteProcessingSQL(ref sql, parameters);
|
||||||
@ -267,10 +278,20 @@ namespace SqlSugar
|
|||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close();
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (this.IsClose()) this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
public virtual object GetScalar(string sql, params SugarParameter[] parameters)
|
public virtual object GetScalar(string sql, params SugarParameter[] parameters)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (this.ProcessingEventStartingSQL != null)
|
if (this.ProcessingEventStartingSQL != null)
|
||||||
ExecuteProcessingSQL(ref sql, parameters);
|
ExecuteProcessingSQL(ref sql, parameters);
|
||||||
@ -281,9 +302,17 @@ namespace SqlSugar
|
|||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close();
|
|
||||||
return scalar;
|
return scalar;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (this.IsClose()) this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -603,6 +632,10 @@ namespace SqlSugar
|
|||||||
if (parameters == null) return null;
|
if (parameters == null) return null;
|
||||||
return base.GetParameters(parameters, propertyInfo, this.SqlParameterKeyWord);
|
return base.GetParameters(parameters, propertyInfo, this.SqlParameterKeyWord);
|
||||||
}
|
}
|
||||||
|
private bool IsClose()
|
||||||
|
{
|
||||||
|
return this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1078,6 +1078,7 @@ namespace SqlSugar
|
|||||||
asyncQueryableBuilder.Parameters = this.QueryBuilder.Parameters;
|
asyncQueryableBuilder.Parameters = this.QueryBuilder.Parameters;
|
||||||
asyncQueryableBuilder.TableShortName = this.QueryBuilder.TableShortName;
|
asyncQueryableBuilder.TableShortName = this.QueryBuilder.TableShortName;
|
||||||
asyncQueryableBuilder.TableWithString = this.QueryBuilder.TableWithString;
|
asyncQueryableBuilder.TableWithString = this.QueryBuilder.TableWithString;
|
||||||
|
asyncQueryableBuilder.GroupByValue = this.QueryBuilder.GroupByValue;
|
||||||
return asyncQueryable;
|
return asyncQueryable;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -219,12 +219,18 @@ namespace SqlSugar
|
|||||||
resolveExpress.Resolve(expression, resolveType);
|
resolveExpress.Resolve(expression, resolveType);
|
||||||
this.Parameters.AddRange(resolveExpress.Parameters);
|
this.Parameters.AddRange(resolveExpress.Parameters);
|
||||||
var reval = resolveExpress.Result;
|
var reval = resolveExpress.Result;
|
||||||
|
var isSingleTableHasSubquery = IsSingle() && resolveExpress.SingleTableNameSubqueryShortName.IsValuable();
|
||||||
|
if (isSingleTableHasSubquery) {
|
||||||
|
Check.Exception(!string.IsNullOrEmpty(this.TableShortName) && resolveExpress.SingleTableNameSubqueryShortName != this.TableShortName, "{0} and {1} need same name");
|
||||||
|
this.TableShortName = resolveExpress.SingleTableNameSubqueryShortName;
|
||||||
|
}
|
||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
public virtual string ToSqlString()
|
public virtual string ToSqlString()
|
||||||
{
|
{
|
||||||
string oldOrderBy = this.OrderByValue;
|
string oldOrderBy = this.OrderByValue;
|
||||||
string externalOrderBy = oldOrderBy;
|
string externalOrderBy = oldOrderBy;
|
||||||
|
var isIgnoreOrderBy = this.IsCount&&this.PartitionByValue.IsNullOrEmpty();
|
||||||
AppendFilter();
|
AppendFilter();
|
||||||
sql = new StringBuilder();
|
sql = new StringBuilder();
|
||||||
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY GetDate() ";
|
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY GetDate() ";
|
||||||
@ -236,10 +242,10 @@ namespace SqlSugar
|
|||||||
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
|
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
|
||||||
string groupByValue = GetGroupByString + HavingInfos;
|
string groupByValue = GetGroupByString + HavingInfos;
|
||||||
string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null;
|
string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null;
|
||||||
if (this.IsCount) { orderByValue = null; }
|
if (isIgnoreOrderBy) { orderByValue = null; }
|
||||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
|
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
|
||||||
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
|
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (isIgnoreOrderBy ? null : rowNumberString) : null);
|
||||||
if (this.IsCount) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
|
if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
|
||||||
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
|
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
|
||||||
if (ExternalPageIndex > 0)
|
if (ExternalPageIndex > 0)
|
||||||
{
|
{
|
||||||
@ -445,7 +451,7 @@ namespace SqlSugar
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (this.OrderByValue == null) return null;
|
if (this.OrderByValue == null) return null;
|
||||||
if (IsCount) return null;
|
if (IsCount&&this.PartitionByValue.IsNullOrEmpty()) return null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return this.OrderByValue;
|
return this.OrderByValue;
|
||||||
|
@ -36,5 +36,12 @@ namespace SqlSugar
|
|||||||
return this.IsLeft == true ? this.BaseParameter.RightExpression : this.BaseParameter.LeftExpression;
|
return this.IsLeft == true ? this.BaseParameter.RightExpression : this.BaseParameter.LeftExpression;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public bool IsSetTempData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return BaseParameter.CommonTempData.IsValuable() && BaseParameter.CommonTempData.Equals(CommonTempDataType.Result);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,12 @@ namespace SqlSugar
|
|||||||
_Result = value;
|
_Result = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public bool LastCharIsSpace{
|
||||||
|
get {
|
||||||
|
if (_Result == null|| _Result.Length==0) return true;
|
||||||
|
return _Result.ToString().Last() == UtilConstants.SpaceChar;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
public string GetString()
|
public string GetString()
|
||||||
{
|
{
|
||||||
|
@ -294,5 +294,20 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return string.Join("", strings);
|
return string.Join("", strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string Pack(string sql)
|
||||||
|
{
|
||||||
|
return "(" + sql + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string EqualTrue(string fieldName)
|
||||||
|
{
|
||||||
|
return "( " + fieldName + "=1 )";
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string Null()
|
||||||
|
{
|
||||||
|
return "NULL";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ namespace SqlSugar
|
|||||||
string DateIsSameDay(MethodCallExpressionModel model);
|
string DateIsSameDay(MethodCallExpressionModel model);
|
||||||
string DateIsSameByType(MethodCallExpressionModel model);
|
string DateIsSameByType(MethodCallExpressionModel model);
|
||||||
string DateAddByType(MethodCallExpressionModel model);
|
string DateAddByType(MethodCallExpressionModel model);
|
||||||
|
|
||||||
string DateValue(MethodCallExpressionModel model);
|
string DateValue(MethodCallExpressionModel model);
|
||||||
string DateAddDay(MethodCallExpressionModel model);
|
string DateAddDay(MethodCallExpressionModel model);
|
||||||
string Between(MethodCallExpressionModel model);
|
string Between(MethodCallExpressionModel model);
|
||||||
@ -52,5 +53,8 @@ namespace SqlSugar
|
|||||||
string False();
|
string False();
|
||||||
string GuidNew();
|
string GuidNew();
|
||||||
string MergeString(params string[] strings);
|
string MergeString(params string[] strings);
|
||||||
|
string EqualTrue(string value);
|
||||||
|
string Pack(string sql);
|
||||||
|
string Null();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,5 +102,11 @@ namespace SqlSugar
|
|||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
|
public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
|
/// <summary>
|
||||||
|
/// Subquery
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
public int ParameterIndex { get; set; }
|
public int ParameterIndex { get; set; }
|
||||||
|
public string SingleTableNameSubqueryShortName{ get; set; }
|
||||||
public MappingColumnList MappingColumns { get; set; }
|
public MappingColumnList MappingColumns { get; set; }
|
||||||
public MappingTableList MappingTables { get; set; }
|
public MappingTableList MappingTables { get; set; }
|
||||||
public IgnoreColumnList IgnoreComumnList { get; set; }
|
public IgnoreColumnList IgnoreComumnList { get; set; }
|
||||||
|
@ -54,7 +54,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else if (expression is ConditionalExpression)
|
else if (expression is ConditionalExpression)
|
||||||
{
|
{
|
||||||
Check.ThrowNotSupportedException("ConditionalExpression");
|
return new ConditionalExpressionResolve(parameter);
|
||||||
}
|
}
|
||||||
else if (expression is MethodCallExpression)
|
else if (expression is MethodCallExpression)
|
||||||
{
|
{
|
||||||
@ -239,9 +239,10 @@ namespace SqlSugar
|
|||||||
protected void AppendNot(object Value)
|
protected void AppendNot(object Value)
|
||||||
{
|
{
|
||||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.FormatSymbol);
|
var isAppend = !this.Context.Result.Contains(ExpressionConst.FormatSymbol);
|
||||||
|
var lastCharIsSpace = this.Context.Result.LastCharIsSpace;
|
||||||
if (isAppend)
|
if (isAppend)
|
||||||
{
|
{
|
||||||
this.Context.Result.Append("NOT");
|
this.Context.Result.Append(lastCharIsSpace?"NOT":" NOT");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,25 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public ConditionalExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
public ConditionalExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
||||||
{
|
{
|
||||||
|
var express = base.Expression as ConditionalExpression;
|
||||||
|
var isLeft = parameter.IsLeft;
|
||||||
|
switch (base.Context.ResolveType)
|
||||||
|
{
|
||||||
|
case ResolveExpressType.None:
|
||||||
|
case ResolveExpressType.WhereSingle:
|
||||||
|
case ResolveExpressType.WhereMultiple:
|
||||||
|
case ResolveExpressType.SelectSingle:
|
||||||
|
case ResolveExpressType.SelectMultiple:
|
||||||
|
case ResolveExpressType.FieldSingle:
|
||||||
|
case ResolveExpressType.FieldMultiple:
|
||||||
|
case ResolveExpressType.Join:
|
||||||
|
case ResolveExpressType.ArraySingle:
|
||||||
|
case ResolveExpressType.ArrayMultiple:
|
||||||
|
case ResolveExpressType.Update:
|
||||||
|
default:
|
||||||
|
Check.Exception(true, "Does not support it.xx==value ? true:false , Use SqlFunc.IIF (it.xx==value,true,false)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ namespace SqlSugar
|
|||||||
if (value == null && parentIsBinary)
|
if (value == null && parentIsBinary)
|
||||||
{
|
{
|
||||||
parameter.BaseParameter.ValueIsNull = true;
|
parameter.BaseParameter.ValueIsNull = true;
|
||||||
value = "NULL";
|
value = this.Context.DbMehtods.Null();
|
||||||
}
|
}
|
||||||
AppendValue(parameter, isLeft, value);
|
AppendValue(parameter, isLeft, value);
|
||||||
}
|
}
|
||||||
|
@ -11,82 +11,162 @@ namespace SqlSugar
|
|||||||
public MemberExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
public MemberExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
||||||
{
|
{
|
||||||
var baseParameter = parameter.BaseParameter;
|
var baseParameter = parameter.BaseParameter;
|
||||||
var isLeft = parameter.IsLeft;
|
|
||||||
var isSetTempData = baseParameter.CommonTempData.IsValuable() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);
|
|
||||||
var expression = base.Expression as MemberExpression;
|
var expression = base.Expression as MemberExpression;
|
||||||
var childExpression = expression.Expression as MemberExpression;
|
var childExpression = expression.Expression as MemberExpression;
|
||||||
|
var memberName = expression.Member.Name;
|
||||||
var childIsMember = childExpression != null;
|
var childIsMember = childExpression != null;
|
||||||
var isValue = expression.Member.Name == "Value" && expression.Member.DeclaringType.Name == "Nullable`1";
|
var isLeft = parameter.IsLeft;
|
||||||
|
var isSetTempData = parameter.IsSetTempData;
|
||||||
|
var isValue = memberName == "Value" && expression.Member.DeclaringType.Name == "Nullable`1";
|
||||||
var isBool = expression.Type == UtilConstants.BoolType;
|
var isBool = expression.Type == UtilConstants.BoolType;
|
||||||
var isValueBool = isValue && isBool && parameter.BaseExpression == null;
|
var isValueBool = isValue && isBool && parameter.BaseExpression == null;
|
||||||
var isLength = expression.Member.Name == "Length" && childIsMember && childExpression.Type == UtilConstants.StringType;
|
var isLength = memberName == "Length" && childIsMember && childExpression.Type == UtilConstants.StringType;
|
||||||
var isDateValue = expression.Member.Name.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == UtilConstants.DateType;
|
var isDateValue = memberName.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == UtilConstants.DateType;
|
||||||
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
|
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
|
||||||
var isHasValue = isLogicOperator && expression.Member.Name == "HasValue" && expression.Expression != null && expression.NodeType == ExpressionType.MemberAccess;
|
var isHasValue = isLogicOperator && memberName == "HasValue" && expression.Expression != null && expression.NodeType == ExpressionType.MemberAccess;
|
||||||
var isDateTimeNowDate = expression.Member.Name == "Date" && childIsMember && childExpression.Member.Name == "Now";
|
var isDateDate = memberName == "Date" && expression.Expression.Type == UtilConstants.DateType;
|
||||||
var isDateDate = expression.Member.Name == "Date" && expression.Expression.Type == UtilConstants.DateType;
|
var isMemberValue = expression.Expression != null && expression.Expression.NodeType != ExpressionType.Parameter && !isValueBool;
|
||||||
|
var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle;
|
||||||
|
|
||||||
if (isLength)
|
if (isLength)
|
||||||
{
|
{
|
||||||
var oldCommonTempDate = parameter.CommonTempData;
|
ResolveLength(parameter, isLeft, expression);
|
||||||
parameter.CommonTempData = CommonTempDataType.Result;
|
|
||||||
this.Expression = expression.Expression;
|
|
||||||
var isConst = this.Expression is ConstantExpression;
|
|
||||||
this.Start();
|
|
||||||
var methodParamter = new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null };
|
|
||||||
var result = this.Context.DbMehtods.Length(new MethodCallExpressionModel()
|
|
||||||
{
|
|
||||||
Args = new List<MethodCallExpressionArgs>() {
|
|
||||||
methodParamter
|
|
||||||
}
|
|
||||||
});
|
|
||||||
base.AppendMember(parameter, isLeft, result);
|
|
||||||
parameter.CommonTempData = oldCommonTempDate;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (isHasValue)
|
else if (isHasValue)
|
||||||
{
|
{
|
||||||
parameter.CommonTempData = CommonTempDataType.Result;
|
ResolveHasValue(parameter, expression);
|
||||||
this.Expression = expression.Expression;
|
|
||||||
this.Start();
|
|
||||||
var methodParamter = new MethodCallExpressionArgs() { IsMember = true, MemberName = parameter.CommonTempData, MemberValue = null };
|
|
||||||
var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel()
|
|
||||||
{
|
|
||||||
Args = new List<MethodCallExpressionArgs>() {
|
|
||||||
methodParamter
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.Context.Result.Append(result);
|
|
||||||
parameter.CommonTempData = null;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (isDateValue)
|
else if (isDateValue)
|
||||||
{
|
{
|
||||||
var name = expression.Member.Name;
|
ResolveDateValue(parameter, isLeft, expression);
|
||||||
var oldCommonTempDate = parameter.CommonTempData;
|
|
||||||
parameter.CommonTempData = CommonTempDataType.Result;
|
|
||||||
this.Expression = expression.Expression;
|
|
||||||
var isConst = this.Expression is ConstantExpression;
|
|
||||||
this.Start();
|
|
||||||
var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
|
|
||||||
{
|
|
||||||
Args = new List<MethodCallExpressionArgs>() {
|
|
||||||
new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null },
|
|
||||||
new MethodCallExpressionArgs() { IsMember = true, MemberName = name, MemberValue = name }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
base.AppendMember(parameter, isLeft, result);
|
|
||||||
parameter.CommonTempData = oldCommonTempDate;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (isValueBool)
|
else if (isValueBool)
|
||||||
{
|
{
|
||||||
isValue = false;
|
ResolveValueBool(parameter, baseParameter, expression, isLeft, isSingle);
|
||||||
}
|
}
|
||||||
else if (isValue)
|
else if (isValue)
|
||||||
{
|
{
|
||||||
expression = expression.Expression as MemberExpression;
|
ResolveValue(parameter, baseParameter, expression, isLeft, isSetTempData, isSingle);
|
||||||
}
|
}
|
||||||
else if (isDateDate)
|
else if (isDateDate)
|
||||||
|
{
|
||||||
|
ResolveDateDate(parameter, isLeft, expression);
|
||||||
|
}
|
||||||
|
else if (isMemberValue)
|
||||||
|
{
|
||||||
|
ResolveMemberValue(parameter, baseParameter, isLeft, isSetTempData, expression);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
baseParameter.ChildExpression = expression;
|
||||||
|
string fieldName = string.Empty;
|
||||||
|
switch (parameter.Context.ResolveType)
|
||||||
|
{
|
||||||
|
case ResolveExpressType.SelectSingle:
|
||||||
|
fieldName = GetSingleName(parameter, expression, isLeft);
|
||||||
|
if (isSetTempData)
|
||||||
|
baseParameter.CommonTempData = fieldName;
|
||||||
|
else
|
||||||
|
base.Context.Result.Append(fieldName);
|
||||||
|
break;
|
||||||
|
case ResolveExpressType.SelectMultiple:
|
||||||
|
fieldName = GetMultipleName(parameter, expression, isLeft);
|
||||||
|
if (isSetTempData)
|
||||||
|
baseParameter.CommonTempData = fieldName;
|
||||||
|
else
|
||||||
|
base.Context.Result.Append(fieldName);
|
||||||
|
break;
|
||||||
|
case ResolveExpressType.WhereSingle:
|
||||||
|
case ResolveExpressType.WhereMultiple:
|
||||||
|
ResolveWhereLogic(parameter, baseParameter, expression, isLeft, isSetTempData, isSingle);
|
||||||
|
break;
|
||||||
|
case ResolveExpressType.FieldSingle:
|
||||||
|
fieldName = GetSingleName(parameter, expression, isLeft);
|
||||||
|
base.Context.Result.Append(fieldName);
|
||||||
|
break;
|
||||||
|
case ResolveExpressType.FieldMultiple:
|
||||||
|
fieldName = GetMultipleName(parameter, expression, isLeft);
|
||||||
|
base.Context.Result.Append(fieldName);
|
||||||
|
break;
|
||||||
|
case ResolveExpressType.ArrayMultiple:
|
||||||
|
case ResolveExpressType.ArraySingle:
|
||||||
|
fieldName = GetName(parameter, expression, isLeft, parameter.Context.ResolveType == ResolveExpressType.ArraySingle);
|
||||||
|
base.Context.Result.Append(fieldName);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Resolve Where
|
||||||
|
private void ResolveWhereLogic(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSetTempData, bool isSingle)
|
||||||
|
{
|
||||||
|
string fieldName = string.Empty;
|
||||||
|
if (isSetTempData)
|
||||||
|
{
|
||||||
|
if (ExpressionTool.IsConstExpression(expression))
|
||||||
|
{
|
||||||
|
var value = ExpressionTool.GetMemberValue(expression.Member, expression);
|
||||||
|
base.AppendValue(parameter, isLeft, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fieldName = GetName(parameter, expression, null, isSingle);
|
||||||
|
baseParameter.CommonTempData = fieldName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ExpressionTool.IsConstExpression(expression))
|
||||||
|
{
|
||||||
|
var value = ExpressionTool.GetMemberValue(expression.Member, expression);
|
||||||
|
base.AppendValue(parameter, isLeft, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fieldName = GetName(parameter, expression, isLeft, isSingle);
|
||||||
|
if (expression.Type == UtilConstants.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
fieldName = this.Context.DbMehtods.EqualTrue(fieldName);
|
||||||
|
}
|
||||||
|
AppendMember(parameter, isLeft, fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Resolve special member
|
||||||
|
private MemberExpression ResolveValue(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSetTempData, bool isSingle)
|
||||||
|
{
|
||||||
|
expression = expression.Expression as MemberExpression;
|
||||||
|
baseParameter.ChildExpression = expression;
|
||||||
|
ResolveWhereLogic(parameter, baseParameter, expression, isLeft, isSetTempData, isSingle);
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResolveValueBool(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool? isLeft, bool isSingle)
|
||||||
|
{
|
||||||
|
string fieldName = GetName(parameter, expression.Expression as MemberExpression, isLeft, isSingle);
|
||||||
|
if (expression.Type == UtilConstants.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
fieldName = this.Context.DbMehtods.EqualTrue(fieldName);
|
||||||
|
}
|
||||||
|
AppendMember(parameter, isLeft, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResolveMemberValue(ExpressionParameter parameter, ExpressionParameter baseParameter, bool? isLeft, bool isSetTempData, MemberExpression expression)
|
||||||
|
{
|
||||||
|
var value = ExpressionTool.GetMemberValue(expression.Member, expression);
|
||||||
|
if (isSetTempData)
|
||||||
|
{
|
||||||
|
baseParameter.CommonTempData = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppendValue(parameter, isLeft, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResolveDateDate(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
|
||||||
{
|
{
|
||||||
var name = expression.Member.Name;
|
var name = expression.Member.Name;
|
||||||
var oldCommonTempDate = parameter.CommonTempData;
|
var oldCommonTempDate = parameter.CommonTempData;
|
||||||
@ -115,101 +195,63 @@ namespace SqlSugar
|
|||||||
this.GetDateValue(parameter.CommonTempData, DateType.Day))));
|
this.GetDateValue(parameter.CommonTempData, DateType.Day))));
|
||||||
}
|
}
|
||||||
parameter.CommonTempData = oldCommonTempDate;
|
parameter.CommonTempData = oldCommonTempDate;
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (isDateTimeNowDate)
|
|
||||||
{
|
|
||||||
AppendValue(parameter, isLeft, DateTime.Now.Date);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (expression.Expression != null && expression.Expression.NodeType != ExpressionType.Parameter && !isValueBool)
|
|
||||||
{
|
|
||||||
var value = ExpressionTool.GetMemberValue(expression.Member, expression);
|
|
||||||
if (isSetTempData)
|
|
||||||
{
|
|
||||||
baseParameter.CommonTempData = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AppendValue(parameter, isLeft, value);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string fieldName = string.Empty;
|
|
||||||
baseParameter.ChildExpression = expression;
|
|
||||||
switch (parameter.Context.ResolveType)
|
|
||||||
{
|
|
||||||
case ResolveExpressType.SelectSingle:
|
|
||||||
fieldName = GetSingleName(parameter, expression, isLeft);
|
|
||||||
if (isSetTempData)
|
|
||||||
{
|
|
||||||
baseParameter.CommonTempData = fieldName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
base.Context.Result.Append(fieldName);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ResolveExpressType.SelectMultiple:
|
|
||||||
fieldName = GetMultipleName(parameter, expression, isLeft);
|
|
||||||
if (isSetTempData)
|
|
||||||
{
|
|
||||||
baseParameter.CommonTempData = fieldName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
base.Context.Result.Append(fieldName);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ResolveExpressType.WhereSingle:
|
|
||||||
case ResolveExpressType.WhereMultiple:
|
|
||||||
var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle;
|
|
||||||
if (isSetTempData)
|
|
||||||
{
|
|
||||||
fieldName = GetName(parameter, expression, null, isSingle);
|
|
||||||
baseParameter.CommonTempData = fieldName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isValueBool)
|
|
||||||
{
|
|
||||||
fieldName = GetName(parameter, expression.Expression as MemberExpression, isLeft, isSingle);
|
|
||||||
}
|
|
||||||
else if (ExpressionTool.IsConstExpression(expression))
|
|
||||||
{
|
|
||||||
var value = ExpressionTool.GetMemberValue(expression.Member, expression);
|
|
||||||
base.AppendValue(parameter, isLeft, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fieldName = GetName(parameter, expression, isLeft, isSingle);
|
|
||||||
}
|
|
||||||
if (expression.Type == UtilConstants.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
fieldName = "( " + fieldName + "=1 )";
|
|
||||||
}
|
|
||||||
fieldName = AppendMember(parameter, isLeft, fieldName);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ResolveExpressType.FieldSingle:
|
|
||||||
fieldName = GetSingleName(parameter, expression, isLeft);
|
|
||||||
base.Context.Result.Append(fieldName);
|
|
||||||
break;
|
|
||||||
case ResolveExpressType.FieldMultiple:
|
|
||||||
fieldName = GetMultipleName(parameter, expression, isLeft);
|
|
||||||
base.Context.Result.Append(fieldName);
|
|
||||||
break;
|
|
||||||
case ResolveExpressType.ArrayMultiple:
|
|
||||||
case ResolveExpressType.ArraySingle:
|
|
||||||
fieldName = GetName(parameter, expression, isLeft, parameter.Context.ResolveType == ResolveExpressType.ArraySingle);
|
|
||||||
base.Context.Result.Append(fieldName);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResolveDateValue(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
|
||||||
|
{
|
||||||
|
var name = expression.Member.Name;
|
||||||
|
var oldCommonTempDate = parameter.CommonTempData;
|
||||||
|
parameter.CommonTempData = CommonTempDataType.Result;
|
||||||
|
this.Expression = expression.Expression;
|
||||||
|
var isConst = this.Expression is ConstantExpression;
|
||||||
|
this.Start();
|
||||||
|
var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
|
||||||
|
{
|
||||||
|
Args = new List<MethodCallExpressionArgs>() {
|
||||||
|
new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null },
|
||||||
|
new MethodCallExpressionArgs() { IsMember = true, MemberName = name, MemberValue = name }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
base.AppendMember(parameter, isLeft, result);
|
||||||
|
parameter.CommonTempData = oldCommonTempDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResolveHasValue(ExpressionParameter parameter, MemberExpression expression)
|
||||||
|
{
|
||||||
|
parameter.CommonTempData = CommonTempDataType.Result;
|
||||||
|
this.Expression = expression.Expression;
|
||||||
|
this.Start();
|
||||||
|
var methodParamter = new MethodCallExpressionArgs() { IsMember = true, MemberName = parameter.CommonTempData, MemberValue = null };
|
||||||
|
var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel()
|
||||||
|
{
|
||||||
|
Args = new List<MethodCallExpressionArgs>() {
|
||||||
|
methodParamter
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.Context.Result.Append(result);
|
||||||
|
parameter.CommonTempData = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResolveLength(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
|
||||||
|
{
|
||||||
|
var oldCommonTempDate = parameter.CommonTempData;
|
||||||
|
parameter.CommonTempData = CommonTempDataType.Result;
|
||||||
|
this.Expression = expression.Expression;
|
||||||
|
var isConst = this.Expression is ConstantExpression;
|
||||||
|
this.Start();
|
||||||
|
var methodParamter = new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null };
|
||||||
|
var result = this.Context.DbMehtods.Length(new MethodCallExpressionModel()
|
||||||
|
{
|
||||||
|
Args = new List<MethodCallExpressionArgs>() {
|
||||||
|
methodParamter
|
||||||
|
}
|
||||||
|
});
|
||||||
|
base.AppendMember(parameter, isLeft, result);
|
||||||
|
parameter.CommonTempData = oldCommonTempDate;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helper
|
||||||
private string AppendMember(ExpressionParameter parameter, bool? isLeft, string fieldName)
|
private string AppendMember(ExpressionParameter parameter, bool? isLeft, string fieldName)
|
||||||
{
|
{
|
||||||
if (parameter.BaseExpression is BinaryExpression || (parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals(CommonTempDataType.Append)))
|
if (parameter.BaseExpression is BinaryExpression || (parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals(CommonTempDataType.Append)))
|
||||||
@ -253,7 +295,7 @@ namespace SqlSugar
|
|||||||
string shortName = expression.Expression.ToString();
|
string shortName = expression.Expression.ToString();
|
||||||
string fieldName = expression.Member.Name;
|
string fieldName = expression.Member.Name;
|
||||||
fieldName = this.Context.GetDbColumnName(expression.Expression.Type.Name, fieldName);
|
fieldName = this.Context.GetDbColumnName(expression.Expression.Type.Name, fieldName);
|
||||||
fieldName = Context.GetTranslationColumnName(shortName + "." + fieldName);
|
fieldName = Context.GetTranslationColumnName(shortName +UtilConstants.Dot+ fieldName);
|
||||||
return fieldName;
|
return fieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,6 +318,7 @@ namespace SqlSugar
|
|||||||
};
|
};
|
||||||
return this.Context.DbMehtods.DateValue(pars);
|
return this.Context.DbMehtods.DateValue(pars);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetToDate(string value)
|
private string GetToDate(string value)
|
||||||
{
|
{
|
||||||
var pars = new MethodCallExpressionModel()
|
var pars = new MethodCallExpressionModel()
|
||||||
@ -286,5 +329,6 @@ namespace SqlSugar
|
|||||||
};
|
};
|
||||||
return this.Context.DbMehtods.ToDate(pars);
|
return this.Context.DbMehtods.ToDate(pars);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,22 @@ namespace SqlSugar
|
|||||||
this.Context.Result.Append(this.Context.DbMehtods.GuidNew());
|
this.Context.Result.Append(this.Context.DbMehtods.GuidNew());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isValidNativeMethod && express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic") && methodName == "Contains")
|
else if (IsSubMethod(express, methodName))
|
||||||
|
{
|
||||||
|
//Check.Exception(!(parameter.BaseExpression is BinaryExpression), "Current expressions are not supported");
|
||||||
|
SubResolve subResolve = new SubResolve(express, this.Context, parameter.OppsiteExpression);
|
||||||
|
var appendSql = subResolve.GetSql();
|
||||||
|
if (this.Context.ResolveType.IsIn(ResolveExpressType.SelectMultiple,ResolveExpressType.SelectSingle))
|
||||||
|
{
|
||||||
|
parameter.BaseParameter.CommonTempData = appendSql;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base.AppendValue(parameter, isLeft, appendSql);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsContainsArray(express, methodName, isValidNativeMethod))
|
||||||
{
|
{
|
||||||
methodName = "ContainsArray";
|
methodName = "ContainsArray";
|
||||||
isValidNativeMethod = true;
|
isValidNativeMethod = true;
|
||||||
@ -117,7 +132,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
this.Context.ResolveType = ResolveExpressType.WhereSingle;
|
this.Context.ResolveType = ResolveExpressType.WhereSingle;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
this.Context.ResolveType = ResolveExpressType.WhereMultiple;
|
this.Context.ResolveType = ResolveExpressType.WhereMultiple;
|
||||||
}
|
}
|
||||||
Where(parameter, isLeft, name, args, model);
|
Where(parameter, isLeft, name, args, model);
|
||||||
@ -198,7 +214,8 @@ namespace SqlSugar
|
|||||||
AppendModelByIIFBinary(parameter, model, item);
|
AppendModelByIIFBinary(parameter, model, item);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (isIFFBoolMethod && !isFirst) {
|
else if (isIFFBoolMethod && !isFirst)
|
||||||
|
{
|
||||||
AppendModelByIIFMethod(parameter, model, item);
|
AppendModelByIIFMethod(parameter, model, item);
|
||||||
}
|
}
|
||||||
else if (isBinaryExpression)
|
else if (isBinaryExpression)
|
||||||
@ -433,6 +450,15 @@ namespace SqlSugar
|
|||||||
{ "AddMilliseconds",DateType.Millisecond}
|
{ "AddMilliseconds",DateType.Millisecond}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private bool IsContainsArray(MethodCallExpression express, string methodName, bool isValidNativeMethod)
|
||||||
|
{
|
||||||
|
return !isValidNativeMethod && express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic") && methodName == "Contains";
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsSubMethod(MethodCallExpression express, string methodName)
|
||||||
|
{
|
||||||
|
return SubTools.SubItemsConst.Any(it => it.Name == methodName) && express.Object != null && express.Object.Type.Name == "Subqueryable`1";
|
||||||
|
}
|
||||||
private void CheckMethod(MethodCallExpression expression)
|
private void CheckMethod(MethodCallExpression expression)
|
||||||
{
|
{
|
||||||
Check.Exception(expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName, string.Format(ErrorMessage.MethodError, expression.Method.Name));
|
Check.Exception(expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName, string.Format(ErrorMessage.MethodError, expression.Method.Name));
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public interface ISubOperation
|
||||||
|
{
|
||||||
|
ExpressionContext Context { get; set; }
|
||||||
|
string Name { get; }
|
||||||
|
string GetValue(Expression expression);
|
||||||
|
int Sort { get; }
|
||||||
|
Expression Expression { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubAnd:ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "And"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 401;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
var argExp = exp.Arguments[0];
|
||||||
|
var result = "AND " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.WhereMultiple);
|
||||||
|
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||||
|
result = result.Replace(selfParameterName, string.Empty);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubAny : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Any";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
return "EXISTS";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubBegin : ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Begin";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
return "SELECT";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubCount: ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Count";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
return "COUNT(*)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubFromTable : ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Subqueryable";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
var resType = exp.Method.ReturnType;
|
||||||
|
var name = resType.GetGenericArguments().First().Name;
|
||||||
|
return "FROM "+this.Context.GetTranslationTableName(name, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubLeftBracket : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "LeftBracket";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
return "(";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubMax:ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Max";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression = null)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
return "MAX("+SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle)+")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubMin: ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Min";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression = null)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
return "MIN(" + SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle) + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubNotAny : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "NotAny";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
return "NOT EXISTS";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubRightBracket : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "RightBracket";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
return ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubSelect : ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Select";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression = null)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
return SubTools.GetMethodValue(this.Context, exp.Arguments[0],ResolveExpressType.FieldSingle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubSelectDefault : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get {
|
||||||
|
return "SelectDefault";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 250;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
return "*";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubTop : ISubOperation
|
||||||
|
{
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Top";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (this.Context is SqlServerExpressionContext)
|
||||||
|
{
|
||||||
|
return 150;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 450;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
if (this.Context is SqlServerExpressionContext)
|
||||||
|
{
|
||||||
|
return "TOP 1";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "limit 0,1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubWhere: ISubOperation
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "Where"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expression Expression
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Sort
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressionContext Context
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(Expression expression)
|
||||||
|
{
|
||||||
|
var exp = expression as MethodCallExpression;
|
||||||
|
var argExp= exp.Arguments[0];
|
||||||
|
var result= "WHERE "+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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
/// ** description:Get subquery sql
|
||||||
|
/// ** author:sunkaixuan
|
||||||
|
/// ** date:2017/9/17
|
||||||
|
/// ** email:610262374@qq.com
|
||||||
|
/// </summary>
|
||||||
|
public class SubResolve
|
||||||
|
{
|
||||||
|
List<MethodCallExpression> allMethods = new List<MethodCallExpression>();
|
||||||
|
private ExpressionContext context = null;
|
||||||
|
private bool hasWhere;
|
||||||
|
public SubResolve(MethodCallExpression expression, ExpressionContext context, Expression oppsiteExpression)
|
||||||
|
{
|
||||||
|
this.context = context;
|
||||||
|
var currentExpression = expression;
|
||||||
|
allMethods.Add(currentExpression);
|
||||||
|
if (context.IsSingle && oppsiteExpression != null&& oppsiteExpression is MemberExpression)
|
||||||
|
{
|
||||||
|
var childExpression = (oppsiteExpression as MemberExpression).Expression;
|
||||||
|
this.context.SingleTableNameSubqueryShortName = (childExpression as ParameterExpression).Name;
|
||||||
|
}
|
||||||
|
else if (context.IsSingle)
|
||||||
|
{
|
||||||
|
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
|
||||||
|
}
|
||||||
|
while (currentExpression != null)
|
||||||
|
{
|
||||||
|
var addItem = currentExpression.Object as MethodCallExpression;
|
||||||
|
if (addItem != null)
|
||||||
|
allMethods.Add(addItem);
|
||||||
|
currentExpression = addItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetSql()
|
||||||
|
{
|
||||||
|
List<string> subItems = GetSubItems();
|
||||||
|
var sql = string.Join(UtilConstants.Space, subItems);
|
||||||
|
return this.context.DbMehtods.Pack(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string> GetSubItems()
|
||||||
|
{
|
||||||
|
var isubList = this.allMethods.Select(exp =>
|
||||||
|
{
|
||||||
|
var methodName = exp.Method.Name;
|
||||||
|
var items = SubTools.SubItems(this.context);
|
||||||
|
var item = items.First(s => s.Name == methodName);
|
||||||
|
if (item is SubWhere && hasWhere == false)
|
||||||
|
{
|
||||||
|
hasWhere = true;
|
||||||
|
}
|
||||||
|
else if (item is SubWhere)
|
||||||
|
{
|
||||||
|
item = items.First(s => s is SubAnd);
|
||||||
|
}
|
||||||
|
item.Context = this.context;
|
||||||
|
item.Expression = exp;
|
||||||
|
return item;
|
||||||
|
}).ToList();
|
||||||
|
isubList.Insert(0, new SubBegin());
|
||||||
|
if (isubList.Any(it => it is SubSelect))
|
||||||
|
{
|
||||||
|
isubList.Add(new SubTop() { Context=this.context });
|
||||||
|
}
|
||||||
|
if (isubList.Any(it => it is SubAny || it is SubNotAny))
|
||||||
|
{
|
||||||
|
isubList.Add(new SubLeftBracket());
|
||||||
|
isubList.Add(new SubRightBracket());
|
||||||
|
isubList.Add(new SubSelectDefault());
|
||||||
|
}
|
||||||
|
isubList = isubList.OrderBy(it => it.Sort).ToList();
|
||||||
|
List<string> result = isubList.Select(it =>
|
||||||
|
{
|
||||||
|
return it.GetValue(it.Expression);
|
||||||
|
}).ToList();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class SubTools
|
||||||
|
{
|
||||||
|
public static List<ISubOperation> SubItems(ExpressionContext Context)
|
||||||
|
{
|
||||||
|
|
||||||
|
return new List<ISubOperation>()
|
||||||
|
{
|
||||||
|
new SubSelect() { Context=Context },
|
||||||
|
new SubWhere(){ Context=Context },
|
||||||
|
new SubAnd(){ Context=Context },
|
||||||
|
new SubAny(){ Context=Context },
|
||||||
|
new SubNotAny(){ Context=Context },
|
||||||
|
new SubBegin(){ Context=Context },
|
||||||
|
new SubFromTable(){ Context=Context },
|
||||||
|
new SubCount(){ Context=Context },
|
||||||
|
new SubMax(){ Context=Context },
|
||||||
|
new SubMin(){ Context=Context }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ISubOperation> SubItemsConst = SubItems(null);
|
||||||
|
|
||||||
|
public static string GetMethodValue(ExpressionContext context, Expression item, ResolveExpressType type)
|
||||||
|
{
|
||||||
|
var newContext = context.GetCopyContext();
|
||||||
|
newContext.MappingColumns = context.MappingColumns;
|
||||||
|
newContext.MappingTables = context.MappingTables;
|
||||||
|
newContext.IgnoreComumnList = context.IgnoreComumnList;
|
||||||
|
newContext.Resolve(item, type);
|
||||||
|
context.Index = newContext.Index;
|
||||||
|
context.ParameterIndex = newContext.ParameterIndex;
|
||||||
|
return newContext.Result.GetResultString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 开发中....
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class Subqueryable<T> where T : class, new()
|
||||||
|
{
|
||||||
|
public Subqueryable<T> Where(Func<T, bool> expression)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TResult Select<TResult>(Func<T, TResult> expression) where TResult :struct
|
||||||
|
{
|
||||||
|
return default(TResult);
|
||||||
|
}
|
||||||
|
public string Select(Func<T, string> expression)
|
||||||
|
{
|
||||||
|
return default(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TResult Max<TResult>(Func<T, TResult> expression) where TResult : struct
|
||||||
|
{
|
||||||
|
return default(TResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TResult Min<TResult>(Func<T, TResult> expression) where TResult : struct
|
||||||
|
{
|
||||||
|
return default(TResult);
|
||||||
|
}
|
||||||
|
public string Max(Func<T, string> expression)
|
||||||
|
{
|
||||||
|
return default(string);
|
||||||
|
}
|
||||||
|
public string Min(Func<T, string> expression)
|
||||||
|
{
|
||||||
|
return default(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Any()
|
||||||
|
{
|
||||||
|
return default(bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool NotAny()
|
||||||
|
{
|
||||||
|
return default(bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Count()
|
||||||
|
{
|
||||||
|
return default(int);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
internal class DependencyManagement
|
||||||
|
{
|
||||||
|
private static bool IsTryJsonNet = false;
|
||||||
|
private static bool IsTryMySqlData = false;
|
||||||
|
private static bool IsTrySqlite = false;
|
||||||
|
public static void TryJsonNet()
|
||||||
|
{
|
||||||
|
if (!IsTryJsonNet)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JsonHelper.SerializeObject(new { });
|
||||||
|
IsTryJsonNet = true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
var message = ErrorMessage.GetThrowMessage(
|
||||||
|
" SqlSugar Some functions are used in newtonsoft ,Nuget references Newtonsoft.Json 9.0.0.1 + .",
|
||||||
|
" SqlSugar 部分功能用到Newtonsoft.Json.dll,需要在Nuget上安装 Newtonsoft.Json 9.0.0.1及以上版本,如果有版本兼容问题请先删除原有引用");
|
||||||
|
throw new Exception(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void TryMySqlData()
|
||||||
|
{
|
||||||
|
if (!IsTryMySqlData)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MySqlProvider db = new MySqlProvider();
|
||||||
|
var conn = db.GetAdapter();
|
||||||
|
IsTryMySqlData = true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
var message = ErrorMessage.GetThrowMessage(
|
||||||
|
"You need to refer to MySql.Data.dll" ,
|
||||||
|
"需要引用MySql.Data.dll,请在Nuget安装最新稳定版本,如果有版本兼容问题请先删除原有引用");
|
||||||
|
throw new Exception(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TrySqlite()
|
||||||
|
{
|
||||||
|
if (!IsTrySqlite)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqliteProvider db = new SqliteProvider();
|
||||||
|
var conn= db.GetAdapter();
|
||||||
|
IsTrySqlite = true;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
var message = ErrorMessage.GetThrowMessage(
|
||||||
|
"You need to refer to Microsoft.Data.Sqlite." + ex.Message,
|
||||||
|
"你需要引用System.Data.SQLite.dll,如果有版本兼容问题请先删除原有引用");
|
||||||
|
throw new Exception(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -281,7 +281,7 @@ namespace SqlSugar
|
|||||||
var result = (Restult)Activator.CreateInstance(type, true);
|
var result = (Restult)Activator.CreateInstance(type, true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private static T CreateInstance<T>(string className)
|
public static T CreateInstance<T>(string className)
|
||||||
{
|
{
|
||||||
Type type;
|
Type type;
|
||||||
if (typeCache.ContainsKey(className))
|
if (typeCache.ContainsKey(className))
|
||||||
|
@ -6,7 +6,6 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public class RewritableMethods : IRewritableMethods
|
public class RewritableMethods : IRewritableMethods
|
||||||
@ -191,9 +190,12 @@ namespace SqlSugar
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string SerializeObject(object value)
|
public string SerializeObject(object value)
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(value);
|
DependencyManagement.TryJsonNet();
|
||||||
|
return JsonHelper.SerializeObject(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serialize Object
|
/// Serialize Object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -201,8 +203,8 @@ namespace SqlSugar
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T DeserializeObject<T>(string value)
|
public T DeserializeObject<T>(string value)
|
||||||
{
|
{
|
||||||
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
DependencyManagement.TryJsonNet();
|
||||||
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
return JsonHelper.DeserializeObject<T>(value);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -255,7 +257,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
deserializeObject.Add(childRow);
|
deserializeObject.Add(childRow);
|
||||||
}
|
}
|
||||||
return JsonConvert.DeserializeObject<dynamic>(JsonConvert.SerializeObject(deserializeObject));
|
return this.DeserializeObject<dynamic>(this.SerializeObject(deserializeObject));
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -21,6 +21,8 @@ namespace SqlSugar
|
|||||||
List<SugarParameter> Parameters { get; set; }
|
List<SugarParameter> Parameters { get; set; }
|
||||||
ExpressionResult Result { get; set; }
|
ExpressionResult Result { get; set; }
|
||||||
string SqlParameterKeyWord { get; }
|
string SqlParameterKeyWord { get; }
|
||||||
|
string SingleTableNameSubqueryShortName { get; set; }
|
||||||
|
|
||||||
string GetAsString(string fieldName, string fieldValue);
|
string GetAsString(string fieldName, string fieldValue);
|
||||||
void Resolve(Expression expression, ResolveExpressType resolveType);
|
void Resolve(Expression expression, ResolveExpressType resolveType);
|
||||||
void Clear();
|
void Clear();
|
||||||
|
@ -22,9 +22,21 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
base.Context = this;
|
base.Context = this;
|
||||||
base.CurrentConnectionConfig = config;
|
base.CurrentConnectionConfig = config;
|
||||||
if (config.DbType == DbType.Oracle)
|
Check.ArgumentNullException(config, "config is null");
|
||||||
|
switch (config.DbType)
|
||||||
{
|
{
|
||||||
|
case DbType.MySql:
|
||||||
|
DependencyManagement.TryMySqlData();
|
||||||
|
break;
|
||||||
|
case DbType.SqlServer:
|
||||||
|
break;
|
||||||
|
case DbType.Sqlite:
|
||||||
|
DependencyManagement.TrySqlite();
|
||||||
|
break;
|
||||||
|
case DbType.Oracle:
|
||||||
throw new Exception("Oracle developed 60%,to be continued");
|
throw new Exception("Oracle developed 60%,to be continued");
|
||||||
|
default:
|
||||||
|
throw new Exception("ConnectionConfig.DbType is null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -71,7 +71,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
List<string> formatArgs = new List<string>() { enMessage, cnMessage };
|
List<string> formatArgs = new List<string>() { enMessage, cnMessage };
|
||||||
formatArgs.AddRange(args);
|
formatArgs.AddRange(args);
|
||||||
return string.Format("\r\n English Message : {0}\r\n Chinese Message : {1}", formatArgs.ToArray());
|
return string.Format(@"English Message : {0}
|
||||||
|
Chinese Message : {1}", formatArgs.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
internal class JsonHelper
|
||||||
|
{
|
||||||
|
public static string SerializeObject(object value)
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T DeserializeObject<T>(string value)
|
||||||
|
{
|
||||||
|
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||||
|
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ namespace SqlSugar
|
|||||||
public const string Dot = ".";
|
public const string Dot = ".";
|
||||||
public const char DotChar = '.';
|
public const char DotChar = '.';
|
||||||
internal const string Space = " ";
|
internal const string Space = " ";
|
||||||
|
internal const char SpaceChar =' ';
|
||||||
internal const string AssemblyName = "SqlSugar";
|
internal const string AssemblyName = "SqlSugar";
|
||||||
internal const string ReplaceKey = "{662E689B-17A1-4D06-9D27-F29EAB8BC3D6}";
|
internal const string ReplaceKey = "{662E689B-17A1-4D06-9D27-F29EAB8BC3D6}";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user