Browse Source

ok

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
4553bae9b0
  1. BIN
      .vs/SqlSugar/v14/.suo
  2. 10
      OrmTest/ExpressionTest/Select.cs
  3. 1
      OrmTest/Models/Student.cs
  4. BIN
      OrmTest/bin/Debug/OrmTest.exe
  5. BIN
      OrmTest/bin/Debug/OrmTest.pdb
  6. BIN
      OrmTest/bin/Debug/SqlSugar.dll
  7. BIN
      OrmTest/bin/Debug/SqlSugar.pdb
  8. 33
      SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

BIN
.vs/SqlSugar/v14/.suo

Binary file not shown.

10
OrmTest/ExpressionTest/Select.cs

@ -23,20 +23,24 @@ namespace OrmTest.ExpressionTest
MultipleDynamic(); MultipleDynamic();
} }
DateTime e = DateTime.Now; DateTime e = DateTime.Now;
Console.WriteLine("Count: "+ count + "\r\nTime: "+(e-b).TotalSeconds+ " Seconds "); Console.WriteLine("Count: " + count + "\r\nTime: " + (e - b).TotalSeconds + " Seconds ");
} }
private static void Multiple() private static void Multiple()
{ {
Expression<Func<Student,School, object>> exp = (it,school) => new Student() { Name = "a", Id = it.Id, SchoolId = school.Id }; Expression<Func<Student, School, object>> exp = (it, school) => new Student() { Name = "a", Id = it.Id, SchoolId = school.Id,TestId=it.Id+1 };
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectMultiple); ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectMultiple);
expContext.Resolve(); expContext.Resolve();
var selectorValue = expContext.Result.GetString(); var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters; var pars = expContext.Parameters;
if (selectorValue.Trim() != " @constant1 AS Name , it.Id AS Id , school.Id AS SchoolId ".Trim())
{
throw new Exception("Multiple Error");
}
} }
private static void MultipleDynamic() private static void MultipleDynamic()
{ {
Expression<Func<Student, School, object>> exp = (it, school) => new{ Name = "a", Id = it.Id/2, SchoolId = school.Id }; Expression<Func<Student, School, object>> exp = (it, school) => new { Name = "a", Id = it.Id / 2, SchoolId = school.Id };
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectMultiple); ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.SelectMultiple);
expContext.Resolve(); expContext.Resolve();
var selectorValue = expContext.Result.GetString(); var selectorValue = expContext.Result.GetString();

1
OrmTest/Models/Student.cs

@ -20,5 +20,6 @@ namespace OrmTest.Models
[SugarColumn(MappingKeys = "id,SchoolId")] [SugarColumn(MappingKeys = "id,SchoolId")]
public virtual School School { get; set; } public virtual School School { get; set; }
public int TestId { get; set; }
} }
} }

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.

33
SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

@ -44,26 +44,45 @@ namespace SqlSugar
throw new NotSupportedException(); throw new NotSupportedException();
} }
MemberAssignment memberAssignment = (MemberAssignment)binding; MemberAssignment memberAssignment = (MemberAssignment)binding;
var memberName = memberAssignment.Member.Name;
var item = memberAssignment.Expression; var item = memberAssignment.Expression;
if (item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant) if (item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
{ {
base.Expression = item; base.Expression = item;
base.Start(); base.Start();
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i; string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
parameter.Context.Result.Append(parameterName); parameter.Context.Result.Append(base.Context.GetAsString(memberName, parameterName));
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData)); this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
} }
else if (item is MemberExpression) else if (item is MemberExpression)
{ {
base.Expression = memberAssignment.Expression; if (base.Context.Result.IsLockCurrentParameter == false)
base.Start(); {
base.Context.Result.CurrentParameter = parameter;
base.Context.Result.IsLockCurrentParameter = true;
parameter.IsAppendTempDate();
base.Expression = item;
base.Start();
parameter.IsAppendResult();
base.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
base.Context.Result.CurrentParameter = null;
}
} }
else if (item is BinaryExpression) else if (item is BinaryExpression)
{ {
base.Expression = item; if (base.Context.Result.IsLockCurrentParameter == false)
parameter.CommonTempData = "simple"; {
base.Start(); base.Context.Result.CurrentParameter = parameter;
parameter.CommonTempData = null; base.Context.Result.IsLockCurrentParameter = true;
parameter.IsAppendTempDate();
base.Expression = item;
parameter.CommonTempData = "simple";
base.Start();
parameter.CommonTempData = null;
parameter.IsAppendResult();
base.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
base.Context.Result.CurrentParameter = null;
}
} }
else else
{ {

Loading…
Cancel
Save