Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
b2202e4518
  1. BIN
      .vs/SqlSugar/v14/.suo
  2. 2
      SqlSugar/ExpressionsToSql/BinaryExpressionInfo.cs
  3. 17
      SqlSugar/ExpressionsToSql/ExpConst.cs
  4. 3
      SqlSugar/ExpressionsToSql/ExpressionContext.cs
  5. 2
      SqlSugar/ExpressionsToSql/ExpressionParameter.cs
  6. 2
      SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  7. 390
      SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs
  8. 3
      SqlSugar/ExpressionsToSql/ResolveItems/LambdaExpressionResolve.cs
  9. 10
      SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

BIN
.vs/SqlSugar/v14/.suo

Binary file not shown.

2
SqlSugar/ExpressionsToSql/BinaryExpressionInfo.cs

@ -9,7 +9,7 @@ namespace SqlSugar
public class BinaryExpressionInfo
{
public bool IsLeft { get; set; }
ExpressionType ExpressionType { get;set;}
public ExpressionType ExpressionType { get;set;}
public object Value { get; set; }
}
}

17
SqlSugar/ExpressionsToSql/ExpConst.cs

@ -7,9 +7,16 @@ namespace SqlSugar
{
internal class ExpConst
{
public const string FiledName = "filedName";
public const string FiledValue = "FiledValue";
public const string Operator = "Operator";
public const string BinaryExpressionInfoListKey = "BinaryExpressionInfoListKey";
public const string BinaryFormatString = " ( {0} {1} {2} ) ";
public const string Format0 = "{0}";
public const string Format1 = "{1}";
internal static string GetThrowMessage(string enMessage, string cnMessage, params string[] args)
{
List<string> formatArgs = new List<string>() { enMessage, cnMessage };
formatArgs.AddRange(args);
return string.Format("\r\n English Message : {0}\r\n Chinese Message : {1}", formatArgs.ToArray());
}
}
internal partial class ErrorMessage
@ -19,7 +26,7 @@ namespace SqlSugar
{
get
{
return GetThrowMessage("拉姆达解析出错:不支持{0}此种运算符查找!",
return ExpConst.GetThrowMessage("拉姆达解析出错:不支持{0}此种运算符查找!",
"Lambda parsing error: {0} does not support the operator to find!");
}
}
@ -27,7 +34,7 @@ namespace SqlSugar
{
get
{
return GetThrowMessage("Expression format error, correct format: it=>it.fieldName",
return ExpConst.GetThrowMessage("Expression format error, correct format: it=>it.fieldName",
"表达示格式错误,正确格式: it=>it.fieldName");
}
}

3
SqlSugar/ExpressionsToSql/ExpressionContext.cs

@ -27,7 +27,8 @@ namespace SqlSugar
{
BaseResolve resolve = new BaseResolve(new ExpressionParameter() { Expression = this.Expression, Context = this });
resolve.Start();
return resolve.SqlWhere;
if (resolve.SqlWhere == null) return string.Empty;
return resolve.SqlWhere.ToString();
}
public List<SugarParameter> Parameters

2
SqlSugar/ExpressionsToSql/ExpressionParameter.cs

@ -13,7 +13,7 @@ namespace SqlSugar
public bool? IsLeft { get; set; }
public Expression BaseExpression { get; set; }
public int Index { get; set; }
public Dictionary<string, object> TempData { get; set; }
public List<KeyValuePair<string, BinaryExpressionInfo>> BinaryExpressionInfoList { get; set; }
public ExpressionParameter BaseParameter { get; set; }
}
}

2
SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -10,7 +10,7 @@ namespace SqlSugar
protected Expression Expression { get; set; }
protected Expression BaseExpression { get; set; }
public ExpressionContext Context { get; set; }
public string SqlWhere { get; set; }
public StringBuilder SqlWhere { get; set; }
public bool? IsLeft { get; set; }
public int ContentIndex { get { return this.Context.Index; } }
public int Index { get; set; }

390
SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -9,9 +9,14 @@ namespace SqlSugar
{
public BinaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
parameter.TempData = new Dictionary<string, object>();
parameter.BinaryExpressionInfoList =new List<KeyValuePair<string, BinaryExpressionInfo>>();
var expression = this.Expression as BinaryExpression;
parameter.TempData.Add(ExpConst.Operator, ExpTool.GetOperator(expression.NodeType));
var operatorValue = ExpTool.GetOperator(expression.NodeType);
var isComparisonOperator =
expression.NodeType != ExpressionType.And &&
expression.NodeType != ExpressionType.AndAlso &&
expression.NodeType != ExpressionType.Or &&
expression.NodeType != ExpressionType.OrElse;
base.BaseExpression = expression;
base.IsLeft = true;
base.Expression = expression.Left;
@ -20,6 +25,387 @@ namespace SqlSugar
base.Expression = expression.Right;
base.Start();
base.IsLeft = null;
string leftString = GetLeftString(parameter);
string rightString = GetRightString(parameter);
string binarySql =string.Format(ExpConst.BinaryFormatString,leftString,operatorValue,rightString);
string sqlWhereString = base.SqlWhere.ToString();
if (base.SqlWhere == null) {
base.SqlWhere = new StringBuilder();
}
if (sqlWhereString.Contains(ExpConst.Format0))
{
base.SqlWhere.Replace(ExpConst.Format0, sqlWhereString);
}
else
{
base.SqlWhere.Append(binarySql);
}
if (sqlWhereString.Contains(ExpConst.Format1))
{
base.SqlWhere.Replace(ExpConst.Format1, ExpConst.Format0);
}
}
private string GetRightString(ExpressionParameter parameter)
{
var info=parameter.BinaryExpressionInfoList.Single(it => it.Value.IsLeft).Value;
switch (info.ExpressionType)
{
case ExpressionType.Add:
break;
case ExpressionType.AddChecked:
break;
case ExpressionType.And:
break;
case ExpressionType.AndAlso:
break;
case ExpressionType.ArrayLength:
break;
case ExpressionType.ArrayIndex:
break;
case ExpressionType.Call:
break;
case ExpressionType.Coalesce:
break;
case ExpressionType.Conditional:
break;
case ExpressionType.Constant:
break;
case ExpressionType.Convert:
break;
case ExpressionType.ConvertChecked:
break;
case ExpressionType.Divide:
break;
case ExpressionType.Equal:
break;
case ExpressionType.ExclusiveOr:
break;
case ExpressionType.GreaterThan:
break;
case ExpressionType.GreaterThanOrEqual:
break;
case ExpressionType.Invoke:
break;
case ExpressionType.Lambda:
break;
case ExpressionType.LeftShift:
break;
case ExpressionType.LessThan:
break;
case ExpressionType.LessThanOrEqual:
break;
case ExpressionType.ListInit:
break;
case ExpressionType.MemberAccess:
break;
case ExpressionType.MemberInit:
break;
case ExpressionType.Modulo:
break;
case ExpressionType.Multiply:
break;
case ExpressionType.MultiplyChecked:
break;
case ExpressionType.Negate:
break;
case ExpressionType.UnaryPlus:
break;
case ExpressionType.NegateChecked:
break;
case ExpressionType.New:
break;
case ExpressionType.NewArrayInit:
break;
case ExpressionType.NewArrayBounds:
break;
case ExpressionType.Not:
break;
case ExpressionType.NotEqual:
break;
case ExpressionType.Or:
break;
case ExpressionType.OrElse:
break;
case ExpressionType.Parameter:
break;
case ExpressionType.Power:
break;
case ExpressionType.Quote:
break;
case ExpressionType.RightShift:
break;
case ExpressionType.Subtract:
break;
case ExpressionType.SubtractChecked:
break;
case ExpressionType.TypeAs:
break;
case ExpressionType.TypeIs:
break;
case ExpressionType.Assign:
break;
case ExpressionType.Block:
break;
case ExpressionType.DebugInfo:
break;
case ExpressionType.Decrement:
break;
case ExpressionType.Dynamic:
break;
case ExpressionType.Default:
break;
case ExpressionType.Extension:
break;
case ExpressionType.Goto:
break;
case ExpressionType.Increment:
break;
case ExpressionType.Index:
break;
case ExpressionType.Label:
break;
case ExpressionType.RuntimeVariables:
break;
case ExpressionType.Loop:
break;
case ExpressionType.Switch:
break;
case ExpressionType.Throw:
break;
case ExpressionType.Try:
break;
case ExpressionType.Unbox:
break;
case ExpressionType.AddAssign:
break;
case ExpressionType.AndAssign:
break;
case ExpressionType.DivideAssign:
break;
case ExpressionType.ExclusiveOrAssign:
break;
case ExpressionType.LeftShiftAssign:
break;
case ExpressionType.ModuloAssign:
break;
case ExpressionType.MultiplyAssign:
break;
case ExpressionType.OrAssign:
break;
case ExpressionType.PowerAssign:
break;
case ExpressionType.RightShiftAssign:
break;
case ExpressionType.SubtractAssign:
break;
case ExpressionType.AddAssignChecked:
break;
case ExpressionType.MultiplyAssignChecked:
break;
case ExpressionType.SubtractAssignChecked:
break;
case ExpressionType.PreIncrementAssign:
break;
case ExpressionType.PreDecrementAssign:
break;
case ExpressionType.PostIncrementAssign:
break;
case ExpressionType.PostDecrementAssign:
break;
case ExpressionType.TypeEqual:
break;
case ExpressionType.OnesComplement:
break;
case ExpressionType.IsTrue:
break;
case ExpressionType.IsFalse:
break;
default:
break;
}
return info.Value.ObjToString();
}
private string GetLeftString(ExpressionParameter parameter)
{
var info = parameter.BinaryExpressionInfoList.Single(it => !it.Value.IsLeft).Value;
switch (info.ExpressionType)
{
case ExpressionType.Add:
break;
case ExpressionType.AddChecked:
break;
case ExpressionType.And:
break;
case ExpressionType.AndAlso:
break;
case ExpressionType.ArrayLength:
break;
case ExpressionType.ArrayIndex:
break;
case ExpressionType.Call:
break;
case ExpressionType.Coalesce:
break;
case ExpressionType.Conditional:
break;
case ExpressionType.Constant:
break;
case ExpressionType.Convert:
break;
case ExpressionType.ConvertChecked:
break;
case ExpressionType.Divide:
break;
case ExpressionType.Equal:
break;
case ExpressionType.ExclusiveOr:
break;
case ExpressionType.GreaterThan:
break;
case ExpressionType.GreaterThanOrEqual:
break;
case ExpressionType.Invoke:
break;
case ExpressionType.Lambda:
break;
case ExpressionType.LeftShift:
break;
case ExpressionType.LessThan:
break;
case ExpressionType.LessThanOrEqual:
break;
case ExpressionType.ListInit:
break;
case ExpressionType.MemberAccess:
break;
case ExpressionType.MemberInit:
break;
case ExpressionType.Modulo:
break;
case ExpressionType.Multiply:
break;
case ExpressionType.MultiplyChecked:
break;
case ExpressionType.Negate:
break;
case ExpressionType.UnaryPlus:
break;
case ExpressionType.NegateChecked:
break;
case ExpressionType.New:
break;
case ExpressionType.NewArrayInit:
break;
case ExpressionType.NewArrayBounds:
break;
case ExpressionType.Not:
break;
case ExpressionType.NotEqual:
break;
case ExpressionType.Or:
break;
case ExpressionType.OrElse:
break;
case ExpressionType.Parameter:
break;
case ExpressionType.Power:
break;
case ExpressionType.Quote:
break;
case ExpressionType.RightShift:
break;
case ExpressionType.Subtract:
break;
case ExpressionType.SubtractChecked:
break;
case ExpressionType.TypeAs:
break;
case ExpressionType.TypeIs:
break;
case ExpressionType.Assign:
break;
case ExpressionType.Block:
break;
case ExpressionType.DebugInfo:
break;
case ExpressionType.Decrement:
break;
case ExpressionType.Dynamic:
break;
case ExpressionType.Default:
break;
case ExpressionType.Extension:
break;
case ExpressionType.Goto:
break;
case ExpressionType.Increment:
break;
case ExpressionType.Index:
break;
case ExpressionType.Label:
break;
case ExpressionType.RuntimeVariables:
break;
case ExpressionType.Loop:
break;
case ExpressionType.Switch:
break;
case ExpressionType.Throw:
break;
case ExpressionType.Try:
break;
case ExpressionType.Unbox:
break;
case ExpressionType.AddAssign:
break;
case ExpressionType.AndAssign:
break;
case ExpressionType.DivideAssign:
break;
case ExpressionType.ExclusiveOrAssign:
break;
case ExpressionType.LeftShiftAssign:
break;
case ExpressionType.ModuloAssign:
break;
case ExpressionType.MultiplyAssign:
break;
case ExpressionType.OrAssign:
break;
case ExpressionType.PowerAssign:
break;
case ExpressionType.RightShiftAssign:
break;
case ExpressionType.SubtractAssign:
break;
case ExpressionType.AddAssignChecked:
break;
case ExpressionType.MultiplyAssignChecked:
break;
case ExpressionType.SubtractAssignChecked:
break;
case ExpressionType.PreIncrementAssign:
break;
case ExpressionType.PreDecrementAssign:
break;
case ExpressionType.PostIncrementAssign:
break;
case ExpressionType.PostDecrementAssign:
break;
case ExpressionType.TypeEqual:
break;
case ExpressionType.OnesComplement:
break;
case ExpressionType.IsTrue:
break;
case ExpressionType.IsFalse:
break;
default:
break;
}
return info.Value.ObjToString();
}
}
}

3
SqlSugar/ExpressionsToSql/ResolveItems/LambdaExpressionResolve.cs

@ -13,7 +13,8 @@ namespace SqlSugar
var expression = lambda.Body;
if (expression.NodeType == ExpressionType.MemberAccess)
{
base.SqlWhere = "(" + ((MemberExpression)expression).Member.Name + "=1)";
string appendString = "(" +((MemberExpression)expression).Member.Name + "=1)";
base.SqlWhere.Append(appendString);
}
else
{

10
SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

@ -14,10 +14,16 @@ namespace SqlSugar
var isSingle = parameter.Context.IsSingle;
string fieldName = string.Empty;
fieldName = isSingle ? expression.Member.Name : expression.Member.ToString();
parameter.BaseParameter.TempData.Add(ExpConst.FiledName, fieldName);
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(IsLeft),
Value = fieldName,
ExpressionType = expression.NodeType
}));
if (isLeft == null && base.SqlWhere == null)
{
base.SqlWhere = fieldName;
base.SqlWhere = new StringBuilder();
base.SqlWhere.Append(fieldName);
}
}
}

Loading…
Cancel
Save