mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-07 14:18:03 +08:00
-
This commit is contained in:
parent
247dade237
commit
bc8fad8275
Binary file not shown.
@ -16,7 +16,7 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
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);
|
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.Single);
|
||||||
// var x = expContext.GetFiledName();
|
// var x = expContext.GetFiledName();
|
||||||
var xx = expContext.ToString();
|
var xx = expContext.ToString();
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,6 +13,8 @@ namespace SqlSugar
|
|||||||
public const string Format1 = "{1}";
|
public const string Format1 = "{1}";
|
||||||
public readonly static Type MemberExpressionType = typeof(MemberExpression);
|
public readonly static Type MemberExpressionType = typeof(MemberExpression);
|
||||||
public readonly static Type ConstantExpressionType = typeof(ConstantExpression);
|
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)
|
internal static string GetThrowMessage(string enMessage, string cnMessage, params string[] args)
|
||||||
{
|
{
|
||||||
List<string> formatArgs = new List<string>() { enMessage, cnMessage };
|
List<string> formatArgs = new List<string>() { enMessage, cnMessage };
|
||||||
|
@ -28,7 +28,7 @@ namespace SqlSugar
|
|||||||
string leftString = GetLeftString(parameter);
|
string leftString = GetLeftString(parameter);
|
||||||
string rightString = GetRightString(parameter);
|
string rightString = GetRightString(parameter);
|
||||||
string binarySql =string.Format(ExpressionConst.BinaryFormatString,leftString,operatorValue,rightString);
|
string binarySql =string.Format(ExpressionConst.BinaryFormatString,leftString,operatorValue,rightString);
|
||||||
string sqlWhereString = base.SqlWhere.ToString();
|
string sqlWhereString = base.SqlWhere.ObjToString();
|
||||||
if (base.SqlWhere == null) {
|
if (base.SqlWhere == null) {
|
||||||
base.SqlWhere = new StringBuilder();
|
base.SqlWhere = new StringBuilder();
|
||||||
}
|
}
|
||||||
@ -50,21 +50,31 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var leftInfo = parameter.BinaryExpressionInfoList.Single(it => it.Value.IsLeft).Value;
|
var leftInfo = parameter.BinaryExpressionInfoList.Single(it => it.Value.IsLeft).Value;
|
||||||
var rightInfo = 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 sqlParameterKeyWord = parameter.Context.SqlParameterKeyWord;
|
||||||
var reval= string.Format("{0}{1}{2}",sqlParameterKeyWord,leftInfo.Value,parameter.Context.Index+parameter.Index);
|
var reval = string.Format("{0}{1}{2}", sqlParameterKeyWord, leftInfo.Value, parameter.Context.Index + parameter.Index);
|
||||||
parameter.Context.Parameters.Add(new SugarParameter(reval,leftInfo.Value));
|
if (parameter.Context.Parameters == null) {
|
||||||
|
parameter.Context.Parameters = new List<SugarParameter>();
|
||||||
|
}
|
||||||
|
parameter.Context.Parameters.Add(new SugarParameter(reval, rightInfo.Value));
|
||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
return leftInfo.Value.ObjToString();
|
return rightInfo.Value.ObjToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetLeftString(ExpressionParameter parameter)
|
private string GetLeftString(ExpressionParameter parameter)
|
||||||
{
|
{
|
||||||
var leftInfo = parameter.BinaryExpressionInfoList.Single(it => it.Value.IsLeft).Value;
|
var leftInfo = parameter.BinaryExpressionInfoList.Single(it => it.Value.IsLeft).Value;
|
||||||
var rightInfo = 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
@ -9,15 +10,15 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public ConstantExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
public ConstantExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
||||||
{
|
{
|
||||||
var expression = base.Expression as MemberExpression;
|
var expression = base.Expression as ConstantExpression;
|
||||||
var isLeft = parameter.IsLeft;
|
var isLeft = parameter.IsLeft;
|
||||||
var isSingle = parameter.Context.IsSingle;
|
var isSingle = parameter.Context.IsSingle;
|
||||||
string value = string.Empty;
|
object value = expression.Value;
|
||||||
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
|
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
|
||||||
{
|
{
|
||||||
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
|
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
|
||||||
{
|
{
|
||||||
IsLeft = Convert.ToBoolean(IsLeft),
|
IsLeft = Convert.ToBoolean(isLeft),
|
||||||
Value = value,
|
Value = value,
|
||||||
ExpressionType = expression.GetType()
|
ExpressionType = expression.GetType()
|
||||||
}));
|
}));
|
||||||
@ -28,5 +29,105 @@ namespace SqlSugar
|
|||||||
base.SqlWhere.Append(value);
|
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;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace SqlSugar
|
|||||||
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
|
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
|
||||||
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
|
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
|
||||||
{
|
{
|
||||||
IsLeft = Convert.ToBoolean(IsLeft),
|
IsLeft = Convert.ToBoolean(isLeft),
|
||||||
Value = fieldName,
|
Value = fieldName,
|
||||||
ExpressionType = expression.GetType()
|
ExpressionType = expression.GetType()
|
||||||
}));
|
}));
|
||||||
|
BIN
SqlSugar/bin/Debug/Newtonsoft.Json.dll
Normal file
BIN
SqlSugar/bin/Debug/Newtonsoft.Json.dll
Normal file
Binary file not shown.
BIN
SqlSugar/bin/Debug/SqlSugar.dll
Normal file
BIN
SqlSugar/bin/Debug/SqlSugar.dll
Normal file
Binary file not shown.
BIN
SqlSugar/bin/Debug/SqlSugar.pdb
Normal file
BIN
SqlSugar/bin/Debug/SqlSugar.pdb
Normal file
Binary file not shown.
BIN
SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache
Normal file
BIN
SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache
Normal file
Binary file not shown.
BIN
SqlSugar/obj/Debug/SqlSugar.dll
Normal file
BIN
SqlSugar/obj/Debug/SqlSugar.dll
Normal file
Binary file not shown.
BIN
SqlSugar/obj/Debug/SqlSugar.pdb
Normal file
BIN
SqlSugar/obj/Debug/SqlSugar.pdb
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user