Browse Source

Update exp to sql

pull/29/head
sunkaixuan 2 years ago
parent
commit
c83511f123
  1. 8
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs
  2. 4
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Append.cs
  3. 25
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

8
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs

@ -157,10 +157,10 @@ namespace SqlSugar
{ {
Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsTranscoding", "SetColumns方式更新不支持IsTranscoding,你可以使用db.Updateable(实体)的方式更新")); Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsTranscoding", "SetColumns方式更新不支持IsTranscoding,你可以使用db.Updateable(实体)的方式更新"));
} }
if (checkIsJson && this.EntityInfo.Columns.Any(it => it.IsJson)) //if (checkIsJson && this.EntityInfo.Columns.Any(it => it.IsJson))
{ //{
Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsJson", "SetColumns方式更新不支持IsJson,你可以使用db.Updateable(实体)的方式更新")); // Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsJson", "SetColumns方式更新不支持IsJson,你可以使用db.Updateable(实体)的方式更新"));
} //}
//if (this.EntityInfo.Columns.Any(it => it.IsArray)) //if (this.EntityInfo.Columns.Any(it => it.IsArray))
//{ //{
// Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsArray", "SetColumns方式更新不支持IsArray,你可以使用db.Updateable(实体)的方式更新")); // Check.Exception(true, ErrorMessage.GetThrowMessage("UpdateColumns no support IsArray", "SetColumns方式更新不支持IsArray,你可以使用db.Updateable(实体)的方式更新"));

4
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Append.cs

@ -141,6 +141,10 @@ namespace SqlSugar
} }
this.Context.Parameters.Add(p); this.Context.Parameters.Add(p);
} }
else if (parameter?.BaseParameter?.CommonTempData.ObjToString() == "IsJon=true")
{
this.Context.Parameters.Add(new SugarParameter(appendValue, new SerializeService().SerializeObject(value)) { IsJson=true});
}
else else
{ {
this.Context.Parameters.Add(new SugarParameter(appendValue, value)); this.Context.Parameters.Add(new SugarParameter(appendValue, value));

25
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -27,9 +28,9 @@ namespace SqlSugar
private void Other(ExpressionParameter parameter) private void Other(ExpressionParameter parameter)
{ {
var expression = this.Expression as BinaryExpression; var expression = this.Expression as BinaryExpression;
if (expression.NodeType == ExpressionType.ArrayIndex) if (expression.NodeType == ExpressionType.ArrayIndex)
{ {
var parameterName=AppendParameter(ExpressionTool.DynamicInvoke(expression)); var parameterName = AppendParameter(ExpressionTool.DynamicInvoke(expression));
base.Context.Result.Append($" {BaseParameter.BaseParameter.OperatorValue} {parameterName} "); base.Context.Result.Append($" {BaseParameter.BaseParameter.OperatorValue} {parameterName} ");
return; return;
} }
@ -43,12 +44,32 @@ namespace SqlSugar
{ {
JoinString(parameter, expression); JoinString(parameter, expression);
} }
else if (IsUpdateJson(parameter,expression, operatorValue))
{
parameter.CommonTempData = "IsJon=true";
DefaultBinary(parameter, expression, operatorValue);
}
else else
{ {
DefaultBinary(parameter, expression, operatorValue); DefaultBinary(parameter, expression, operatorValue);
} }
} }
private bool IsUpdateJson(ExpressionParameter parameter,BinaryExpression expression, string operatorValue)
{
var isOk= parameter.Context.ResolveType==ResolveExpressType.WhereSingle&&operatorValue == "=" && (expression.Left is MemberExpression) && expression.Left.Type.IsClass();
if (isOk&&this.Context.SugarContext != null)
{
var entity = this.Context.SugarContext.Context.EntityMaintenance.GetEntityInfo(expression.Left.Type);
var jsonColumn=entity.Columns.FirstOrDefault(it => it.IsJson && it.PropertyName == ExpressionTool.GetMemberName(expression.Left)) ;
if (jsonColumn != null)
{
return true;
}
}
return false;
}
private void JoinString(ExpressionParameter parameter, BinaryExpression expression) private void JoinString(ExpressionParameter parameter, BinaryExpression expression)
{ {
var leftString = GetNewExpressionValue(expression.Left); var leftString = GetNewExpressionValue(expression.Left);

Loading…
Cancel
Save