Beispiel #1
0
        private void HandleSelectManyCall(MethodCallExpression call)
        {
            //get the association path for the joined entity
            var collectionSelector = (LambdaExpression)LinqUtil.StripQuotes(call.Arguments[1]);

            LambdaExpression resultSelector = null;

            if (call.Arguments.Count == 3)
            {
                resultSelector = (LambdaExpression)LinqUtil.StripQuotes(call.Arguments[2]);
                string alias = resultSelector.Parameters[1].Name;

                var visitor = new SelectManyVisitor(rootCriteria, alias);
                visitor.Visit(collectionSelector.Body);
            }

            if (resultSelector != null)
            {
                //visit the result selector expression after the alias for the association has been created
                var resultSelectorVisitor = new SelectArgumentsVisitor(rootCriteria, session);
                resultSelectorVisitor.Visit(resultSelector.Body);

                rootCriteria.SetProjectionIfNotNull(resultSelectorVisitor.Projection);
                rootCriteria.SetResultTransformerIfNotNull(resultSelectorVisitor.Transformer);
            }
        }
Beispiel #2
0
        private void HandleSelectCall(MethodCallExpression call)
        {
            var lambda = (LambdaExpression)LinqUtil.StripQuotes(call.Arguments[1]);

            var visitor = new SelectArgumentsVisitor(rootCriteria, session);

            visitor.Visit(lambda.Body);

            rootCriteria.SetProjectionIfNotNull(visitor.Projection);
            rootCriteria.SetResultTransformerIfNotNull(visitor.Transformer);
        }
        protected override Expression VisitMethodCall(MethodCallExpression expr)
        {
            if (expr.Arguments.Count > 1)
            {
                LambdaExpression lambda = LinqUtil.StripQuotes(expr.Arguments[1]) as LambdaExpression;
                if (lambda != null)
                {
                    _currentCollectionAliases = lambda.Parameters;
                }
            }

            return(base.VisitMethodCall(expr));
        }
        protected override Expression VisitMethodCall(MethodCallExpression call)
        {
            if (call.Method.Name == "SelectMany")
            {
                if (call.Arguments.Count == 3)
                {
                    var    resultSelector = (LambdaExpression)LinqUtil.StripQuotes(call.Arguments[2]);
                    string alias          = resultSelector.Parameters[1].Name;

                    _associationPathsToInclude.Add(alias);
                }
            }

            return(base.VisitMethodCall(call));
        }
        private T HandleAggregateCallback(MethodCallExpression call)
        {
            LambdaExpression lambda = (LambdaExpression)LinqUtil.StripQuotes(call.Arguments[call.Arguments.Count - 1]);

            System.Type resultType = lambda.Parameters[1].Type;

            IList       list       = rootCriteria.List();
            MethodInfo  castMethod = typeof(Enumerable).GetMethod("Cast").MakeGenericMethod(resultType);
            IEnumerable enumerable = (IEnumerable)castMethod.Invoke(null, new object[] { list });

            if (call.Arguments.Count == 2)
            {
                return((T)call.Method.Invoke(null, new object[]
                {
                    enumerable.AsQueryable(),
                    lambda
                }));
            }
            else if (call.Arguments.Count == 3)
            {
                return((T)call.Method.Invoke(null, new[]
                {
                    enumerable.AsQueryable(),
                    ((ConstantExpression)call.Arguments[1]).Value,
                    lambda
                }));
            }
            else if (call.Arguments.Count == 4)
            {
                return((T)call.Method.Invoke(null, new[]
                {
                    enumerable.AsQueryable(),
                    ((ConstantExpression)call.Arguments[1]).Value,
                    LinqUtil.StripQuotes(call.Arguments[2]),
                    lambda
                }));
            }

            throw new ArgumentException("Invalid number of arguments passed to the Aggregate method.");
        }
Beispiel #6
0
        private ICriterion GetExistsCriteria(MethodCallExpression expr)
        {
            EntityExpression rootEntity   = EntityExpressionVisitor.FirstEntity(expr);
            string           propertyName = MemberNameVisitor.GetMemberName(rootCriteria, expr);

            var rootEntityType = rootEntity.Type;

            if (rootEntity.MetaData.HasProxy)
            {
                rootEntityType = rootEntity.MetaData.GetMappedClass(EntityMode.Poco);
            }

            DetachedCriteria query = DetachedCriteria.For(rootEntityType)
                                     .SetProjection(Projections.Id())
                                     .Add(Restrictions.IsNotEmpty(propertyName));

            if (expr.Arguments.Count > 1)
            {
                var    arg   = (LambdaExpression)LinqUtil.StripQuotes(expr.Arguments[1]);
                string alias = arg.Parameters[0].Name;

                DetachedCriteria subquery = query.CreateCriteria(propertyName, alias);

                var temp = new WhereArgumentsVisitor(subquery.Adapt(session), session);
                temp.Visit(arg.Body);

                foreach (ICriterion c in temp.CurrentCriterions)
                {
                    subquery.Add(c);
                }
            }

            string identifierName = rootEntity.GetAliasedIdentifierPropertyName();

            return(Subqueries.PropertyIn(identifierName, query));
        }