SqlSugar/OrmTest/ExpressionTest/Select.cs

44 lines
1.3 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 19:35:22 +08:00
2017-01-14 20:04:23 +08:00
single();
singleDynamic();
2017-01-14 19:35:22 +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;
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";
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
}
}
}