Пример #1
0
        public override Expression VisitCollectionNotEmpty(CollectionNotEmptyExpression expression, Type argument)
        {
            Expression property = Visit(expression.TargetCollection, argument);

            Type elementType = CollectionConverter.TryGetCollectionElementType(property.Type);

            if (elementType == null)
            {
                throw new InvalidOperationException("Expression must be a collection.");
            }

            Expression predicate = null;

            if (expression.Filter != null)
            {
                var hasManyThrough     = expression.TargetCollection.Fields.Last() as HasManyThroughAttribute;
                var lambdaScopeFactory = new LambdaScopeFactory(_nameFactory, hasManyThrough);
                using LambdaScope lambdaScope = lambdaScopeFactory.CreateScope(elementType);

                var builder = new WhereClauseBuilder(property, lambdaScope, typeof(Enumerable), _nameFactory);
                predicate = builder.GetPredicateLambda(expression.Filter);
            }

            return(AnyExtensionMethodCall(elementType, property, predicate));
        }
Пример #2
0
        public override Expression VisitCollectionNotEmpty(CollectionNotEmptyExpression expression, Type argument)
        {
            Expression property = Visit(expression.TargetCollection, argument);

            Type elementType = CollectionConverter.TryGetCollectionElementType(property.Type);

            if (elementType == null)
            {
                throw new InvalidOperationException("Expression must be a collection.");
            }

            return(AnyExtensionMethodCall(elementType, property));
        }