SqlSugar/OrmTest/ExpressionTest/Select.cs

60 lines
1.8 KiB
C#
Raw Normal View History

2017-01-14 15:16:20 +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 Select
{
internal static void Init()
2017-01-14 20:12:39 +08:00
{
DateTime b = DateTime.Now;
int count = 10000;
for (int i = 0; i < count; i++)
{
single();
Multiple();
singleDynamic();
MultipleDynamic();
}
DateTime e = DateTime.Now;
Console.WriteLine("Count: "+ count + "\r\nTime: "+(e-b).TotalSeconds+ " Seconds ");
}
private static void Multiple()
2017-01-14 15:16:20 +08:00
{
2017-01-14 19:35:22 +08:00
}
2017-01-14 20:12:39 +08:00
private static void MultipleDynamic()
{
2017-01-14 19:35:22 +08:00
2017-01-14 20:12:39 +08:00
}
2017-01-14 20:04:23 +08:00
private static void single()
2017-01-14 19:35:22 +08:00
{
2017-01-14 20:04:23 +08:00
int p = 1;
2017-01-14 20:12:39 +08:00
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id = it.Id, SchoolId = p };
2017-01-14 19:35:22 +08:00
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.ResolveType = ResolveExpressType.SelectSingle;
expContext.Resolve();
2017-01-14 20:04:23 +08:00
var selectorValue = expContext.Result.GetString();
2017-01-14 19:35:22 +08:00
var pars = expContext.Parameters;
}
2017-01-14 20:04:23 +08:00
private static void singleDynamic()
2017-01-14 19:35:22 +08:00
{
2017-01-14 20:04:23 +08:00
string a = "a";
2017-01-14 20:12:39 +08:00
Expression<Func<Student, object>> exp = it => new { x = it.Id, shoolid = 1, name = a };
2017-01-14 15:16:20 +08:00
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.ResolveType = ResolveExpressType.SelectSingle;
2017-01-14 19:15:54 +08:00
expContext.Resolve();
2017-01-14 20:04:23 +08:00
var selectorValue = expContext.Result.GetString();
2017-01-14 19:35:22 +08:00
var pars = expContext.Parameters;
2017-01-14 15:16:20 +08:00
}
}
}