You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
61 lines
2.0 KiB
8 years ago
|
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;
|
||
|
|
||
8 years ago
|
namespace OrmTest.UnitTest
|
||
8 years ago
|
{
|
||
8 years ago
|
public class Field : UnitTestBase
|
||
8 years ago
|
{
|
||
8 years ago
|
private Field() { }
|
||
|
public Field(int eachCount)
|
||
8 years ago
|
{
|
||
8 years ago
|
this.Count = eachCount;
|
||
8 years ago
|
}
|
||
8 years ago
|
internal void Init()
|
||
|
{
|
||
|
base.Begin();
|
||
|
for (int i = 0; i < base.Count; i++)
|
||
|
{
|
||
|
FieldSingle();
|
||
|
FieldMultiple();
|
||
7 years ago
|
FieldMultiple2();
|
||
8 years ago
|
}
|
||
|
base.End("Filed Test");
|
||
|
}
|
||
|
private void FieldSingle()
|
||
8 years ago
|
{
|
||
|
Expression<Func<Student, object>> exp = it => it.Name;
|
||
8 years ago
|
ExpressionContext expContext = GetContext();
|
||
8 years ago
|
expContext.Resolve(exp, ResolveExpressType.FieldSingle);
|
||
8 years ago
|
var selectorValue = expContext.Result.GetString();
|
||
8 years ago
|
Check(selectorValue, null, expContext.GetTranslationColumnName("Name"), null, "FieldSingle error");
|
||
8 years ago
|
}
|
||
8 years ago
|
private void FieldMultiple()
|
||
8 years ago
|
{
|
||
|
Expression<Func<Student, object>> exp = it => it.Name;
|
||
8 years ago
|
ExpressionContext expContext = GetContext();
|
||
8 years ago
|
expContext.Resolve(exp, ResolveExpressType.FieldMultiple);
|
||
8 years ago
|
var selectorValue = expContext.Result.GetString();
|
||
8 years ago
|
Check(selectorValue, null, expContext.GetTranslationColumnName("it.Name"), null, "FieldMultiple error");
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
private void FieldMultiple2()
|
||
|
{
|
||
|
Expression<Func<Student, object>> exp = it =>SqlFunc.AggregateAvg(it.Id);
|
||
|
ExpressionContext expContext = GetContext();
|
||
|
expContext.Resolve(exp, ResolveExpressType.FieldMultiple);
|
||
|
var selectorValue = expContext.Result.GetString();
|
||
|
Check(selectorValue, null, "AVG([it].[Id])", null, "FieldMultiple error");
|
||
|
}
|
||
8 years ago
|
public ExpressionContext GetContext()
|
||
|
{
|
||
|
return new SqlServerExpressionContext();//可以更换
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|