protected virtual Expression ApplyInclude(Expression source, IncludeExpression include, ResourceContext resourceContext) { using var lambdaScope = _lambdaScopeFactory.CreateScope(_elementType); var builder = new IncludeClauseBuilder(source, lambdaScope, resourceContext, _resourceContextProvider); return(builder.ApplyInclude(include)); }
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)); }
private Expression CreateAssignmentRightHandSideForLayer(QueryLayer layer, LambdaScope outerLambdaScope, MemberExpression propertyAccess, PropertyInfo selectorPropertyInfo, LambdaScopeFactory lambdaScopeFactory) { Type collectionElementType = TypeHelper.TryGetCollectionElementType(selectorPropertyInfo.PropertyType); Type bodyElementType = collectionElementType ?? selectorPropertyInfo.PropertyType; if (collectionElementType != null) { return(CreateCollectionInitializer(outerLambdaScope, selectorPropertyInfo, bodyElementType, layer, lambdaScopeFactory)); } if (layer.Projection == null || !layer.Projection.Any()) { return(propertyAccess); } using var scope = lambdaScopeFactory.CreateScope(bodyElementType, propertyAccess); return(CreateLambdaBodyInitializer(layer.Projection, layer.ResourceContext, scope, true)); }