Add SetContext(exp)

This commit is contained in:
sunkaixuan 2022-11-10 14:04:30 +08:00
parent dbaaa80902
commit eb4d5152e3
2 changed files with 20 additions and 0 deletions

View File

@ -9,6 +9,7 @@ using System.Text.RegularExpressions;
using System.Reflection;
using System.Dynamic;
using System.Threading.Tasks;
using Newtonsoft.Json.Serialization;
namespace SqlSugar
{
@ -389,6 +390,24 @@ namespace SqlSugar
InitMapping();
return _ToList<T>();
}
public List<T> SetContext<ParameterT>(Expression<Func<T, bool>> whereExpression, ParameterT parameter)
{
var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext<ParameterT>;
var rootList = queryableContext.list;
List<ISugarQueryable<object>> queryableList = new List<ISugarQueryable<object>>();
var index = rootList.IndexOf(parameter);
var selector = this.Clone().QueryBuilder.GetSelectValue+$",{index} as ";
var sqlObj=this.Clone().Where(whereExpression).Select(selector+"")
.Select(it => (object) new { it, sql_sugar_index = index });
queryableList.Add(sqlObj);
var allList = this.Context.Union(queryableList)
.Select(it=>new { it=default(T), sql_sugar_index =0})
.Select("*").ToList();
var result = new List<T>();
throw new Exception("开发中");
return result;
}
public List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter)
{
if (parameter == null)

View File

@ -153,6 +153,7 @@ namespace SqlSugar
List<TResult> ToList<TResult>(Expression<Func<T, TResult>> expression);
Task<List<TResult>> ToListAsync<TResult>(Expression<Func<T, TResult>> expression);
List<T> ToList();
List<T> SetContext<ParameterT>(Expression<Func<T, bool>> whereExpression, ParameterT parameter);
List<T> SetContext<ParameterT>(Expression<Func<T,object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter);
List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled1, Expression<Func<object>> mappingFiled1, Expression<Func<T, object>> thisFiled2, Expression<Func<object>> mappingFiled2, ParameterT parameter);
Task <List<T>> SetContextAsync<ParameterT>(Expression<Func<T, object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter);