SqlSugar/OrmTest/ExpressionTest/Method.cs

70 lines
2.7 KiB
C#
Raw Normal View History

2017-01-28 21:56:15 +08:00
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 Method : ExpTestBase
{
private Method() { }
public Method(int eachCount)
{
this.Count = eachCount;
}
internal void Init()
{
base.Begin();
for (int i = 0; i < base.Count; i++)
{
2017-01-30 15:10:54 +08:00
StringIsNullOrEmpty();
2017-01-30 15:41:16 +08:00
StringIsNullOrEmpty2();
2017-01-30 16:42:33 +08:00
StringIsNullOrEmpty3();
2017-01-28 21:56:15 +08:00
}
base.End("Method Test");
}
2017-01-30 15:10:54 +08:00
private void StringIsNullOrEmpty()
{
Expression<Func<Student, bool>> exp = it =>it.Id>2|| NBORM.IsNullOrEmpty(it.Id);;
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( Id > @Id0 ) OR ( Id='' OR Id IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@Id0",2)
2017-01-30 15:41:16 +08:00
}, "StringIsNullOrEmpty");
}
private void StringIsNullOrEmpty2()
{
Expression<Func<Student, bool>> exp = it => 2==it.Id || NBORM.IsNullOrEmpty(true); ;
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
2017-01-30 16:42:33 +08:00
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodCost1='' OR @MethodCost1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodCost1",true),
2017-01-30 15:41:16 +08:00
new SugarParameter("@Id0",2)
}, "StringIsNullOrEmpty2");
2017-01-30 15:10:54 +08:00
}
2017-01-30 16:42:33 +08:00
private void StringIsNullOrEmpty3()
{
int a = 1;
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(a); ;
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodCost1='' OR @MethodCost1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodCost1",1),
new SugarParameter("@Id0",2)
}, "StringIsNullOrEmpty3");
}
2017-01-28 21:56:15 +08:00
}
}
2017-01-30 15:41:16 +08:00