Пример #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 TableLikeQueryContext(sourceContext);
                    mergeContext.Sequences    = new IBuildContext[] { mergeContext.Sequence, source };
                    mergeContext.Merge.Source = source.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 TableLikeQueryContext(sourceContext);
                    mergeContext.Sequences    = new IBuildContext[] { mergeContext.Sequence, source };
                    mergeContext.Merge.Source = source.Source;
                }

                return(mergeContext);
            }
Пример #2
0
        public IBuildContext BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
        {
            var collectionType = typeof(IEnumerable <>).GetGenericType(buildInfo.Expression.Type) ??
                                 throw new InvalidOperationException();

            var enumerableContext = new EnumerableContext(builder, buildInfo, buildInfo.SelectQuery, collectionType.GetGenericArguments()[0]);

            return(enumerableContext);
        }