Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
92e0699c47
  1. BIN
      .vs/SqlSugar/v14/.suo
  2. 22
      OrmTest/ExpressionTest/Field.cs
  3. 14
      OrmTest/ExpressionTest/Select.cs
  4. 1
      OrmTest/OrmTest.csproj
  5. 1
      OrmTest/Program.cs
  6. BIN
      OrmTest/bin/Debug/OrmTest.exe
  7. BIN
      OrmTest/bin/Debug/OrmTest.pdb
  8. BIN
      OrmTest/bin/Debug/SqlSugar.dll
  9. BIN
      OrmTest/bin/Debug/SqlSugar.pdb
  10. BIN
      OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache
  11. BIN
      OrmTest/obj/Debug/OrmTest.exe
  12. BIN
      OrmTest/obj/Debug/OrmTest.pdb
  13. 7
      SqlSugar/ExpressionsToSql/ExpressionContext.cs
  14. 25
      SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs
  15. 25
      SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs
  16. 20
      SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs
  17. 9
      SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs
  18. 1
      SqlSugar/SqlSugarClient.cs
  19. BIN
      SqlSugar/bin/Debug/SqlSugar.dll
  20. BIN
      SqlSugar/bin/Debug/SqlSugar.pdb
  21. BIN
      SqlSugar/obj/Debug/SqlSugar.dll
  22. BIN
      SqlSugar/obj/Debug/SqlSugar.pdb

BIN
.vs/SqlSugar/v14/.suo

Binary file not shown.

22
OrmTest/ExpressionTest/Field.cs

@ -0,0 +1,22 @@
using OrmTest.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.ExpressionTest
{
public class Field
{
internal static void Init()
{
Expression<Func<Student, object>> exp = it=>it.Name;
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.FieldMultiple);
expContext.Resolve();
var selectorValue = expContext.Result.GetString();
}
}
}

14
OrmTest/ExpressionTest/Select.cs

@ -14,7 +14,7 @@ namespace OrmTest.ExpressionTest
internal static void Init()
{
DateTime b = DateTime.Now;
int count = 10000;
int count = 1;
for (int i = 0; i < count; i++)
{
single();
@ -29,8 +29,7 @@ namespace OrmTest.ExpressionTest
private static void Multiple()
{
Expression<Func<Student,School, object>> exp = (it,school) => new Student() { Name = "a", Id = it.Id, SchoolId = school.Id };
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.ResolveType = ResolveExpressType.SelectMultiple;
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectMultiple);
expContext.Resolve();
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -38,8 +37,7 @@ namespace OrmTest.ExpressionTest
private static void MultipleDynamic()
{
Expression<Func<Student, School, object>> exp = (it, school) => new{ Name = "a", Id = it.Id, SchoolId = school.Id };
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.ResolveType = ResolveExpressType.SelectMultiple;
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectMultiple);
expContext.Resolve();
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -48,8 +46,7 @@ namespace OrmTest.ExpressionTest
{
int p = 1;
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id = it.Id, SchoolId = p };
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.ResolveType = ResolveExpressType.SelectSingle;
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectSingle);
expContext.Resolve();
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -59,8 +56,7 @@ namespace OrmTest.ExpressionTest
{
string a = "a";
Expression<Func<Student, object>> exp = it => new { x = it.Id, shoolid = 1, name = a };
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.ResolveType = ResolveExpressType.SelectSingle;
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectSingle);
expContext.Resolve();
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;

1
OrmTest/OrmTest.csproj

@ -43,6 +43,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExpressionTest\Field.cs" />
<Compile Include="ExpressionTest\Select.cs" />
<Compile Include="ExpressionTest\Where.cs" />
<Compile Include="Models\School.cs" />

1
OrmTest/Program.cs

@ -24,6 +24,7 @@ namespace OrmTest
OrmTest.ExpressionTest.Select.Init();
OrmTest.ExpressionTest.Field.Init();
Program.id = "xx";

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.

7
SqlSugar/ExpressionsToSql/ExpressionContext.cs

@ -7,6 +7,11 @@ using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
///<summary>
/// ** description:Expression to sql
/// ** author:sunkaixuan
/// ** date:2017/1/14
/// ** qq:610262374
public class ExpressionContext : ExpResolveAccessory
{
#region constructor
@ -24,7 +29,7 @@ namespace SqlSugar
#region properties
public IDbMethods DbMehtods { get; set; }
public int Index { get; set; }
public ResolveExpressType ResolveType { get; set; }
internal ResolveExpressType ResolveType { get; set; }
public Expression Expression { get; set; }
public ExpressionResult Result
{

25
SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs

@ -13,14 +13,25 @@ namespace SqlSugar
var expression = base.Expression as ConstantExpression;
var isLeft = parameter.IsLeft;
object value = expression.Value;
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
switch (parameter.Context.ResolveType)
{
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(isLeft),
Value = value,
ExpressionType = expression.GetType()
}));
case ResolveExpressType.WhereSingle:
case ResolveExpressType.WhereMultiple:
case ResolveExpressType.SelectSingle:
case ResolveExpressType.SelectMultiple:
case ResolveExpressType.FieldSingle:
case ResolveExpressType.FieldMultiple:
default:
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
{
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(isLeft),
Value = value,
ExpressionType = expression.GetType()
}));
}
break;
}
}
}

25
SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs

@ -14,14 +14,25 @@ namespace SqlSugar
var expression = base.Expression as MemberExpression;
var isLeft = parameter.IsLeft;
object value = ExpressionTool.GetMemberValue(expression.Member, expression);
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
switch (parameter.Context.ResolveType)
{
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(isLeft),
Value = value,
ExpressionType = expression.Expression.GetType()
}));
case ResolveExpressType.WhereSingle:
case ResolveExpressType.WhereMultiple:
case ResolveExpressType.SelectSingle:
case ResolveExpressType.SelectMultiple:
case ResolveExpressType.FieldSingle:
case ResolveExpressType.FieldMultiple:
default:
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
{
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
IsLeft = Convert.ToBoolean(isLeft),
Value = value,
ExpressionType = expression.Expression.GetType()
}));
}
break;
}
}
}

20
SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

@ -15,29 +15,39 @@ namespace SqlSugar
switch (parameter.Context.ResolveType)
{
case ResolveExpressType.WhereSingle:
fieldName = GetFieldNameByWhereSingle(parameter, expression, isLeft);
fieldName = getSingleName(parameter, expression, isLeft);
base.Context.Result.Append(fieldName);
break;
case ResolveExpressType.WhereMultiple:
fieldName = GetFiledNameByWhereMultiple(parameter, expression, isLeft);
fieldName = getMultipleName(parameter, expression, isLeft);
base.Context.Result.Append(fieldName);
break;
case ResolveExpressType.SelectSingle:
fieldName = getSingleName(parameter, expression, isLeft);
base.Context.Result.Append(fieldName);
break;
case ResolveExpressType.SelectMultiple:
fieldName = getMultipleName(parameter, expression, isLeft);
base.Context.Result.Append(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;
default:
break;
}
}
private string GetFiledNameByWhereMultiple(ExpressionParameter parameter, MemberExpression expression, bool? isLeft)
private string getMultipleName(ExpressionParameter parameter, MemberExpression expression, bool? isLeft)
{
string fieldName = expression.Member.ToString();
string shortName = expression.Expression.ToString();
string fieldName = expression.Member.Name;
fieldName = shortName + "." + fieldName;
if (parameter.BaseParameter.BinaryExpressionInfoList != null)
parameter.BaseParameter.BinaryExpressionInfoList.Add(new KeyValuePair<string, BinaryExpressionInfo>(ExpressionConst.BinaryExpressionInfoListKey, new BinaryExpressionInfo()
{
@ -48,7 +58,7 @@ namespace SqlSugar
return fieldName;
}
private string GetFieldNameByWhereSingle(ExpressionParameter parameter, MemberExpression expression, bool? isLeft)
private string getSingleName(ExpressionParameter parameter, MemberExpression expression, bool? isLeft)
{
string fieldName = expression.Member.Name;
if (parameter.BaseParameter.BinaryExpressionInfoList != null)

9
SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

@ -53,6 +53,7 @@ namespace SqlSugar
}
else
{
var memberExpression = (MemberExpression)memberAssignment.Expression;
if (memberExpression.Expression.NodeType.IsIn(ExpressionType.Constant))
{
@ -61,7 +62,7 @@ namespace SqlSugar
parameter.Context.Result.Append(parameterName);
this.Context.Parameters.Add(new SugarParameter(parameterName, value));
}
else
else if (memberExpression.Expression.NodeType.IsIn(ExpressionType.Parameter))
{
var fieldNme = (memberExpression).Member.Name;
if (isSingle)
@ -71,9 +72,13 @@ namespace SqlSugar
else
{
var shortName = memberExpression.Expression.ToString();
parameter.Context.Result.Append(shortName+"."+fieldNme);
parameter.Context.Result.Append(shortName + "." + fieldNme);
}
}
else
{
Check.ThrowNotSupportedException(memberExpression.Expression.NodeType.ToString());
}
}
}
}

1
SqlSugar/SqlSugarClient.cs

@ -9,6 +9,7 @@ namespace SqlSugar
/// ** description:Create database access object
/// ** author:sunkaixuan
/// ** date:2017/1/2
/// ** qq:610262374
/// </summary>
public partial class SqlSugarClient : SqlSugarAccessory, IDisposable
{

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.dll

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.pdb

Binary file not shown.
Loading…
Cancel
Save