/// <summary> /// 获取表达式的执行计划。 /// </summary> /// <param name="expression"></param> /// <returns></returns> public Expression GetExecutionPlan(Expression expression) { try { if (expression is LambdaExpression lambda) { expression = lambda.Body; } var section = ConfigurationUnity.GetSection <TranslatorConfigurationSection>(); var trans = service.InitializeContext.Provider.GetTranslateProvider(); var options = GetTranslateOptions(); using (var scope = new TranslateScope(service, trans, options)) { var translation = trans.Translate(expression); var translator = trans.CreateTranslator(); return(ExecutionBuilder.Build(translation, e => translator.Translate(e))); } } catch (Exception ex) { throw new TranslateException(expression, ex); } }
public static Expression Build(Expression expression, Expression provider, TranslatorBase translator) { var executor = Expression.Constant(translator.InternalContext.Database); var builder = new ExecutionBuilder() { executor = executor, translator = translator }; return(builder.Bind(expression)); }
/// <summary> /// 构造最终执行的表达式。 /// </summary> /// <param name="expression"></param> /// <param name="translator">翻译器。</param> /// <returns></returns> public static Expression Build(Expression expression, Func <Expression, TranslateResult> translator) { //定义 IDatabase 参数,最终交给IDatabase执行 var executor = Expression.Parameter(typeof(IDatabase), "db"); var builder = new ExecutionBuilder() { executor = executor, translator = translator }; var newExpression = Expression.Convert(builder.Bind(expression), typeof(object)); return(Expression.Lambda(newExpression, executor)); }
private Expression BuildInner(Expression expression) { var eb = new ExecutionBuilder(); eb.executor = executor; eb.scope = this.scope; eb.receivingMember = receivingMember; eb.nReaders = nReaders; eb.nLookup = nLookup; eb.translator = translator; eb.variableMap = variableMap; return(eb.Visit(expression)); }
/// <summary> /// 构造最终执行的表达式。 /// </summary> /// <param name="expression"></param> /// <param name="translator">翻译器。</param> /// <returns></returns> public static Expression Build(Expression expression, Func <Expression, TranslateResult> translator, bool?isAsync = null) { var builder = new ExecutionBuilder() { executor = Expression.Parameter(typeof(IDatabase), "db"), translator = translator }; if (isAsync != null) { builder.isAsync = (bool)isAsync; } var newExpression = builder.Bind(expression); if (builder.isAsync) { var cancelToken = builder.cancelToken ?? Expression.Parameter(typeof(CancellationToken), "token"); return(Expression.Lambda(newExpression, builder.executor, cancelToken)); } return(Expression.Lambda(newExpression, builder.executor)); }