Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
bc8fad8275
  1. BIN
      .vs/SqlSugar/v14/.suo
  2. 2
      OrmTest/Program.cs
  3. BIN
      OrmTest/bin/Debug/OrmTest.exe
  4. BIN
      OrmTest/bin/Debug/OrmTest.pdb
  5. BIN
      OrmTest/bin/Debug/SqlSugar.dll
  6. BIN
      OrmTest/bin/Debug/SqlSugar.pdb
  7. BIN
      OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache
  8. BIN
      OrmTest/obj/Debug/OrmTest.exe
  9. BIN
      OrmTest/obj/Debug/OrmTest.pdb
  10. 2
      SqlSugar/ExpressionsToSql/ExpressionConst.cs
  11. 22
      SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs
  12. 107
      SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs
  13. 2
      SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs
  14. BIN
      SqlSugar/bin/Debug/Newtonsoft.Json.dll
  15. BIN
      SqlSugar/bin/Debug/SqlSugar.dll
  16. BIN
      SqlSugar/bin/Debug/SqlSugar.pdb
  17. BIN
      SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache
  18. BIN
      SqlSugar/obj/Debug/SqlSugar.dll
  19. BIN
      SqlSugar/obj/Debug/SqlSugar.pdb

BIN
.vs/SqlSugar/v14/.suo

Binary file not shown.

2
OrmTest/Program.cs

@ -16,7 +16,7 @@ namespace OrmTest
{
static void Main(string[] args)
{
Expression<Func<Student, bool>> exp = it => it.Name!="";
Expression<Func<Student, bool>> exp = it => it.Name!="a";
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.Single);
// var x = expContext.GetFiledName();
var xx = expContext.ToString();

BIN
OrmTest/bin/Debug/OrmTest.exe

Binary file not shown.

BIN
OrmTest/bin/Debug/OrmTest.pdb

Binary file not shown.

BIN
OrmTest/bin/Debug/SqlSugar.dll

Binary file not shown.

BIN
OrmTest/bin/Debug/SqlSugar.pdb

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.exe

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.pdb

Binary file not shown.

2
SqlSugar/ExpressionsToSql/ExpressionConst.cs

@ -13,6 +13,8 @@ namespace SqlSugar
public const string Format1 = "{1}";
public readonly static Type MemberExpressionType = typeof(MemberExpression);
public readonly static Type ConstantExpressionType = typeof(ConstantExpression);
public readonly static Type StringType = typeof(string);
internal static string GetThrowMessage(string enMessage, string cnMessage, params string[] args)
{
List<string> formatArgs = new List<string>() { enMessage, cnMessage };

22
SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -28,7 +28,7 @@ namespace SqlSugar
string leftString = GetLeftString(parameter);
string rightString = GetRightString(parameter);
string binarySql =string.Format(ExpressionConst.BinaryFormatString,leftString,operatorValue,rightString);
string sqlWhereString = base.SqlWhere.ToString();
string sqlWhereString = base.SqlWhere.ObjToString();
if (base.SqlWhere == null) {
base.SqlWhere = new StringBuilder();
}
@ -50,21 +50,31 @@ namespace SqlSugar
{
var leftInfo = parameter.BinaryExpressionInfoList.Single(it => it.Value.IsLeft).Value;
var rightInfo = parameter.BinaryExpressionInfoList.Single(it => !it.Value.IsLeft).Value;
if (leftInfo.ExpressionType == ExpressionConst.ConstantExpressionType)
if (rightInfo.ExpressionType == ExpressionConst.ConstantExpressionType)
{
var sqlParameterKeyWord = parameter.Context.SqlParameterKeyWord;
var reval= string.Format("{0}{1}{2}",sqlParameterKeyWord,leftInfo.Value,parameter.Context.Index+parameter.Index);
parameter.Context.Parameters.Add(new SugarParameter(reval,leftInfo.Value));
var reval = string.Format("{0}{1}{2}", sqlParameterKeyWord, leftInfo.Value, parameter.Context.Index + parameter.Index);
if (parameter.Context.Parameters == null) {
parameter.Context.Parameters = new List<SugarParameter>();
}
parameter.Context.Parameters.Add(new SugarParameter(reval, rightInfo.Value));
return reval;
}
return leftInfo.Value.ObjToString();
return rightInfo.Value.ObjToString();
}
private string GetLeftString(ExpressionParameter parameter)
{
var leftInfo = parameter.BinaryExpressionInfoList.Single(it => it.Value.IsLeft).Value;
var rightInfo = parameter.BinaryExpressionInfoList.Single(it => !it.Value.IsLeft).Value;
return rightInfo.Value.ObjToString();
if (leftInfo.ExpressionType == ExpressionConst.ConstantExpressionType)
{
var sqlParameterKeyWord = parameter.Context.SqlParameterKeyWord;
var reval = string.Format("{0}{1}{2}", sqlParameterKeyWord, leftInfo.Value, parameter.Context.Index + parameter.Index);
parameter.Context.Parameters.Add(new SugarParameter(reval, leftInfo.Value));
return reval;
}
return leftInfo.Value.ObjToString();
}
}
}

107
SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace SqlSugar
{
@ -9,15 +10,15 @@ namespace SqlSugar
{
public ConstantExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
var expression = base.Expression as MemberExpression;
var expression = base.Expression as ConstantExpression;
var isLeft = parameter.IsLeft;
var isSingle = parameter.Context.IsSingle;
string value = string.Empty;
object value = expression.Value;
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
{
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(IsLeft),
IsLeft = Convert.ToBoolean(isLeft),
Value = value,
ExpressionType = expression.GetType()
}));
@ -28,5 +29,105 @@ namespace SqlSugar
base.SqlWhere.Append(value);
}
}
//private object GetValue(MemberInfo member, Expression expression)
//{
// var memberInfos = new Stack<MemberInfo>();
// var fieldInfo = member as System.Reflection.FieldInfo;
// object dynInv = null;
// // "descend" toward's the root object reference:
// while (expression is MemberExpression)
// {
// var memberExpr = expression as MemberExpression;
// memberInfos.Push(memberExpr.Member);
// if (memberExpr.Expression == null)
// {
// if (memberExpr.Member.MemberType == MemberTypes.Property)
// {
// PropertyInfo pro = (PropertyInfo)memberExpr.Member;
// dynInv = pro.GetValue(memberExpr.Member, null);
// if (dynInv != null && dynInv.GetType().IsClass)
// {
// var fieldName = memberExpr.Member.Name;
// var proInfo = dynInv.GetType().GetProperty(fieldName);
// if (proInfo != null)
// {
// dynInv = proInfo.GetValue(dynInv, null);
// }
// var fieInfo = dynInv.GetType().GetField(fieldName);
// if (fieInfo != null)
// {
// dynInv = fieInfo.GetValue(dynInv);
// }
// if (fieInfo == null && proInfo == null)
// {
// }
// }
// }
// else if (memberExpr.Member.MemberType == MemberTypes.Field)
// {
// FieldInfo field = (FieldInfo)memberExpr.Member;
// dynInv = field.GetValue(memberExpr.Member);
// if (dynInv != null && dynInv.GetType().IsClass && dynInv.GetType() != ExpressionConst.StringType)
// {
// var fieldName = memberExpr.Member.Name;
// var proInfo = dynInv.GetType().GetProperty(fieldName);
// if (proInfo != null)
// {
// dynInv = proInfo.GetValue(dynInv, null);
// }
// var fieInfo = dynInv.GetType().GetField(fieldName);
// if (fieInfo != null)
// {
// dynInv = fieInfo.GetValue(dynInv);
// }
// if (fieInfo == null && proInfo == null)
// {
// }
// }
// }
// }
// if (memberExpr.Expression == null)
// {
// }
// expression = memberExpr.Expression;
// }
// // fetch the root object reference:
// var constExpr = expression as ConstantExpression;
// if (constExpr == null)
// {
// }
// var objReference = constExpr.Value;
// // "ascend" back whence we came from and resolve object references along the way:
// while (memberInfos.Count > 0) // or some other break condition
// {
// var mi = memberInfos.Pop();
// if (mi.MemberType == MemberTypes.Property)
// {
// var objProp = objReference.GetType().GetProperty(mi.Name);
// if (objProp == null)
// {
// }
// objReference = objProp.GetValue(objReference, null);
// }
// else if (mi.MemberType == MemberTypes.Field)
// {
// var objField = objReference.GetType().GetField(mi.Name);
// if (objField == null)
// {
// }
// objReference = objField.GetValue(objReference);
// }
// }
// return dynInv;
//}
}
}

2
SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

@ -17,7 +17,7 @@ namespace SqlSugar
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(IsLeft),
IsLeft = Convert.ToBoolean(isLeft),
Value = fieldName,
ExpressionType = expression.GetType()
}));

BIN
SqlSugar/bin/Debug/Newtonsoft.Json.dll

Binary file not shown.

BIN
SqlSugar/bin/Debug/SqlSugar.dll

Binary file not shown.

BIN
SqlSugar/bin/Debug/SqlSugar.pdb

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.dll

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.pdb

Binary file not shown.
Loading…
Cancel
Save