Exemple #1
0
            protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
            {
                var mergeContext = (MergeContext)builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));

                if (LinqExtensions.UsingMethodInfo1 == methodCall.Method.GetGenericMethodDefinition())
                {
                    var sourceContext = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[1], new SelectQuery()));
                    var source        = new MergeSourceQueryContext(mergeContext.Merge, sourceContext);
                    mergeContext.Sequences = new IBuildContext[] { mergeContext.Sequence, source };
                }
                else
                {
                    var enumerableBuildInfo = new BuildInfo(buildInfo, methodCall.Arguments[1], new SelectQuery());

                    var sourceContext = Find(builder, enumerableBuildInfo, (index, type) =>
                    {
                        var query      = enumerableBuildInfo.SelectQuery;
                        var innerQuery = new SelectQuery {
                            ParentSelect = query
                        };
                        var elements = index switch
                        {
                            4 => BuildElements(type, (IEnumerable)((ConstantExpression)enumerableBuildInfo.Expression).Value),
                            _ => throw new InvalidOperationException(),
                        };
                        return(new EnumerableContext(builder, enumerableBuildInfo, query, type, elements));
                    });
            protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
            {
                var mergeContext = (MergeContext)builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));

                if (LinqExtensions.UsingMethodInfo1 == methodCall.Method.GetGenericMethodDefinition())
                {
                    var sourceContext = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[1], new SelectQuery()));
                    var source        = new MergeSourceQueryContext(mergeContext.Merge, sourceContext);
                    mergeContext.Sequences = new IBuildContext[] { mergeContext.Sequence, source };
                }
                else
                {
                    var enumerableBuildInfo = new BuildInfo(buildInfo, methodCall.Arguments[1], new SelectQuery());

                    var type          = FindType(builder, enumerableBuildInfo);
                    var sourceContext = new EnumerableContext(builder, enumerableBuildInfo,
                                                              enumerableBuildInfo.SelectQuery, type,
                                                              builder.ConvertToSql(buildInfo.Parent, enumerableBuildInfo.Expression));

                    var source = new MergeSourceQueryContext(mergeContext.Merge, sourceContext);
                    mergeContext.Sequences = new IBuildContext[] { mergeContext.Sequence, source };
                }

                return(mergeContext);
            }
            protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
            {
                var mergeContext = (MergeContext)builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));

                var source = new MergeSourceQueryContext(
                    mergeContext.Merge,
                    // is it ok to reuse context like that?
                    mergeContext.TargetContext);

                mergeContext.Sequences = new IBuildContext[] { mergeContext.Sequence, source };

                return(mergeContext);
            }
Exemple #4
0
            protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
            {
                // MergeInto<TTarget, TSource>(IQueryable<TSource> source, ITable<TTarget> target, string hint)
                var sourceContext = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0], new SelectQuery()));
                var target        = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[1])
                {
                    AssociationsAsSubQueries = true
                });
                var targetTable = ((TableBuilder.TableContext)target).SqlTable;

                var merge = new SqlMergeStatement(targetTable)
                {
                    Hint = (string?)methodCall.Arguments[2].EvaluateExpression()
                };

                target.SetAlias(merge.Target.Alias !);
                target.Statement = merge;

                var source = new MergeSourceQueryContext(merge, sourceContext);

                return(new MergeContext(merge, target, source));
            }