예제 #1
0
파일: Intersect.cs 프로젝트: jeswin/AgileFx
            public override Expression Translate(MethodCallExpression mce, Expression translatedSource1, IEnumerable <System.Linq.Expressions.Expression> otherArgs, QueryAnalysisContext context)
            {
                var translatedSource2 = QueryTranslationVisitor.VisitWithNewVisitor(otherArgs.Single(), context, false).TranslatedExpression;

                if (translatedSource1.Type != translatedSource2.Type)
                {
                    throw new Exception("Intersecting queries must be of the same shape.");
                }

                var newArgs = new Expression[]
                {
                    translatedSource1,
                    translatedSource2
                };

                var translatedMethod = mce.Method.GetGenericMethodDefinition().MakeGenericMethod(context.QueryableType.NonPrimitiveEnumerableItemType.TranslatedType);

                return(Expression.Call(mce.Object, translatedMethod, newArgs));
            }
예제 #2
0
            public override Expression Translate(MethodCallExpression mce, Expression translatedSource1, IEnumerable <Expression> otherArgs, QueryAnalysisContext context)
            {
                var translatedSource2 = QueryTranslationVisitor.VisitWithNewVisitor(otherArgs.Single(), context, context.ModifyProjection).TranslatedExpression;

                if (translatedSource1.Type != translatedSource2.Type)
                {
                    throw new Exception("Queries joined with a Union must be similar.");
                }

                var newArgs = new Expression[]
                {
                    translatedSource1,
                    translatedSource2
                };

                var translatedMethod = mce.Method.GetGenericMethodDefinition().MakeGenericMethod(context.QueryableType.NonPrimitiveEnumerableItemType.TranslatedType);

                return(Expression.Call(mce.Object, translatedMethod, newArgs));
            }
예제 #3
0
파일: Join.cs 프로젝트: jeswin/AgileFx
            public override Expression Translate(MethodCallExpression mce, Expression translatedOuter, IEnumerable <Expression> otherArgs, QueryAnalysisContext context)
            {
                bool isQueryable = DefinedOnQueryable(mce);

                var _otherArgs = otherArgs.ToArray();

                //IEnumerable<TInner>
                var innerTranslation = QueryTranslationVisitor.VisitWithNewVisitor(_otherArgs[0], context, false);

                //Func<TOuter, TKey>
                var outerKeySelectorTranslation = QueryTranslationVisitor.TranslateLambda(_otherArgs[1], new[] { context.QueryableType.NonPrimitiveEnumerableItemType }, context, isQueryable);

                //Func<TInner, TKey>
                var innerKeySelectorTranslation = QueryTranslationVisitor.TranslateLambda(_otherArgs[2], new[] { innerTranslation.QueryableType.NonPrimitiveEnumerableItemType }, context, isQueryable);

                //Func<TOuter, TInner, TResult>
                var resultSelectorTranslation = QueryTranslationVisitor.TranslateLambda(_otherArgs[3], new[] { context.QueryableType.NonPrimitiveEnumerableItemType, innerTranslation.QueryableType.NonPrimitiveEnumerableItemType }, context, isQueryable);

                var newArgs = new Expression[]
                {
                    translatedOuter,
                    innerTranslation.TranslatedExpression,
                    outerKeySelectorTranslation.TranslatedExpression,
                    innerKeySelectorTranslation.TranslatedExpression,
                    resultSelectorTranslation.TranslatedExpression
                };

                //Join<TOuter, TInner, TKey, TResult>
                var translatedMethod = mce.Method.GetGenericMethodDefinition().MakeGenericMethod(
                    context.QueryableType.NonPrimitiveEnumerableItemType.TranslatedType,
                    innerTranslation.QueryableType.NonPrimitiveEnumerableItemType.TranslatedType,
                    outerKeySelectorTranslation.QueryableType.TranslatedType,
                    resultSelectorTranslation.QueryableType.TranslatedType);

                context.QueryableType = RuntimeTypes.CreateEnumerable(resultSelectorTranslation.QueryableType);

                return(Expression.Call(mce.Object, translatedMethod, newArgs));
            }
예제 #4
0
            public override Expression Translate(MethodCallExpression mce, Expression translatedSource1, IEnumerable <Expression> otherArgs, QueryAnalysisContext context)
            {
                if (context.QueryableType.NonPrimitiveEnumerableItemType is ProjectedType)
                {
                    throw new NotSupportedException("Contains cannot be called after projection.");
                }

                var translatedSource2 = QueryTranslationVisitor.VisitWithNewVisitor(otherArgs.Single(), context, false).TranslatedExpression;
                var newArgs           = new Expression[]
                {
                    translatedSource1,
                    translatedSource2
                };

                //If NonPrimitiveEnumerableItemType is not null (case 1), this means we have to change the method's generic args.
                //Otherwise, re-use the same (case 2).
                //The second case occurs when we have a List<int> (for example), which has NonPrimitiveEnumerableItemType = null.
                var translatedMethod = context.QueryableType.NonPrimitiveEnumerableItemType != null?
                                       mce.Method.GetGenericMethodDefinition().MakeGenericMethod(context.QueryableType.NonPrimitiveEnumerableItemType.TranslatedType)
                                           : mce.Method;

                context.QueryableType = new SimpleType(typeof(bool), typeof(bool));
                return(Expression.Call(mce.Object, translatedMethod, newArgs));
            }