2017-01-07 21:54:51 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace SqlSugar
|
|
|
|
|
{
|
|
|
|
|
public class QueryableAccessory
|
|
|
|
|
{
|
2017-01-08 00:16:37 +08:00
|
|
|
|
protected List<SugarParameter> _Pars;
|
2017-01-07 21:54:51 +08:00
|
|
|
|
protected void AddPars(object whereObj, SqlSugarClient context)
|
|
|
|
|
{
|
|
|
|
|
var sqlParsArray = context.Database.GetParameters(whereObj);
|
|
|
|
|
if (_Pars == null)
|
2017-01-08 00:16:37 +08:00
|
|
|
|
_Pars = new List<SugarParameter>();
|
2017-01-07 21:54:51 +08:00
|
|
|
|
if (sqlParsArray != null)
|
|
|
|
|
_Pars.AddRange(sqlParsArray);
|
|
|
|
|
}
|
2017-01-08 00:16:37 +08:00
|
|
|
|
protected void AddPars(List<SugarParameter> pars, SqlSugarClient context)
|
2017-01-07 21:54:51 +08:00
|
|
|
|
{
|
|
|
|
|
if (_Pars == null)
|
2017-01-08 00:16:37 +08:00
|
|
|
|
_Pars = new List<SugarParameter>();
|
2017-01-07 21:54:51 +08:00
|
|
|
|
if (pars != null)
|
|
|
|
|
_Pars.AddRange(pars);
|
|
|
|
|
}
|
|
|
|
|
protected void Where<T>(Expression<Func<T, bool>> expression, ResolveExpressType type, SqlSugarClient context) where T : class, new()
|
|
|
|
|
{
|
|
|
|
|
var sqlBuilder = context.SqlBuilder;
|
|
|
|
|
var items = sqlBuilder.LambadaQueryBuilder;
|
|
|
|
|
ResolveExpress resolveExpress = new ResolveExpress(context);
|
|
|
|
|
items.WhereIndex = items.WhereIndex + 100;
|
|
|
|
|
resolveExpress.ResolveExpression(expression);
|
|
|
|
|
this.AddPars(resolveExpress.Paras, context);
|
|
|
|
|
items.WhereInfos.Add(resolveExpress.SqlWhere);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Where<T>(string whereString, object whereObj, SqlSugarClient context) where T : class, new()
|
|
|
|
|
{
|
|
|
|
|
var SqlBuilder = context.SqlBuilder;
|
|
|
|
|
var whereValue = SqlBuilder.LambadaQueryBuilder.WhereInfos;
|
|
|
|
|
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString));
|
|
|
|
|
this.AddPars(whereObj, context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|