mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-01 19:03:58 +08:00
-
This commit is contained in:
@@ -9,26 +9,38 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.ExpressionTest
|
||||
{
|
||||
public class Field
|
||||
public class Field:ExpTestBase
|
||||
{
|
||||
internal static void Init()
|
||||
private Field() { }
|
||||
public Field(int eachCount)
|
||||
{
|
||||
FieldSingle();
|
||||
FieldMultiple();
|
||||
this.Count = eachCount;
|
||||
}
|
||||
private static void FieldSingle()
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
FieldSingle();
|
||||
FieldMultiple();
|
||||
}
|
||||
base.End("Filed Test");
|
||||
}
|
||||
private void FieldSingle()
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => it.Name;
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.FieldSingle);
|
||||
expContext.Resolve();
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
Check(selectorValue, null, "Name", null, "FieldSingle");
|
||||
}
|
||||
private static void FieldMultiple()
|
||||
private void FieldMultiple()
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => it.Name;
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.FieldMultiple);
|
||||
expContext.Resolve();
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
Check(selectorValue, null, "it.Name", null, "FieldMultiple");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,80 @@
|
||||
using System;
|
||||
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 Where
|
||||
public class Where : ExpTestBase
|
||||
{
|
||||
private Where() { }
|
||||
public Where(int eachCount)
|
||||
{
|
||||
this.Count = eachCount;
|
||||
}
|
||||
internal void Init()
|
||||
{
|
||||
base.Begin();
|
||||
for (int i = 0; i < base.Count; i++)
|
||||
{
|
||||
whereSingle1();
|
||||
whereSingle2();
|
||||
whereSingle3();
|
||||
whereSingle4();
|
||||
}
|
||||
base.End("Where Test");
|
||||
}
|
||||
|
||||
private void whereSingle1()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 1;
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
|
||||
expContext.Resolve();
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ( Id > @Id1 ) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id1",1)
|
||||
}, "whereSingle1");
|
||||
}
|
||||
private void whereSingle2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 1 || it.Name == "a";
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
|
||||
expContext.Resolve();
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ( Id > @Id1 ) OR ( Name = @Name2 ) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id1",1),
|
||||
new SugarParameter("@Name2","a")
|
||||
}, "whereSingle2");
|
||||
}
|
||||
private void whereSingle3()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => it.Id > 1 || it.Name == "a";
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
|
||||
expContext.Resolve();
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ( Id > @Id1 ) OR ( Name = @Name2 ) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id1",1),
|
||||
new SugarParameter("@Name2","a")
|
||||
}, "whereSingle2");
|
||||
}
|
||||
private void whereSingle4()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it =>( it.Id > 1 &&it.Name!="a")|| it.Name == "a";
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
|
||||
expContext.Resolve();
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, " ( Id > @Id1 ) OR ( Name = @Name2 ) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id1",1),
|
||||
new SugarParameter("@Name2","a")
|
||||
}, "whereSingle4");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace OrmTest
|
||||
{
|
||||
int eachCount = 1;
|
||||
new OrmTest.ExpressionTest.Select(eachCount).Init();
|
||||
OrmTest.ExpressionTest.Field.Init();
|
||||
new OrmTest.ExpressionTest.Field(eachCount).Init();
|
||||
new OrmTest.ExpressionTest.Where(eachCount).Init();
|
||||
|
||||
|
||||
// Program.id = "xx";
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user