protected virtual IDictionary <ResourceFieldAttribute, QueryLayer> GetSparseFieldSetProjection(IReadOnlyCollection <QueryExpression> expressionsInScope, ResourceContext resourceContext) { if (expressionsInScope == null) { throw new ArgumentNullException(nameof(expressionsInScope)); } if (resourceContext == null) { throw new ArgumentNullException(nameof(resourceContext)); } var attributes = expressionsInScope.OfType <SparseFieldSetExpression>().SelectMany(sparseFieldSet => sparseFieldSet.Attributes).ToHashSet(); var tempExpression = attributes.Any() ? new SparseFieldSetExpression(attributes) : null; tempExpression = _resourceDefinitionAccessor.OnApplySparseFieldSet(resourceContext.ResourceType, tempExpression); attributes = tempExpression == null ? new HashSet <AttrAttribute>() : tempExpression.Attributes.ToHashSet(); if (!attributes.Any()) { return(null); } var idAttribute = resourceContext.Attributes.Single(x => x.Property.Name == nameof(Identifiable.Id)); attributes.Add(idAttribute); return(attributes.Cast <ResourceFieldAttribute>().ToDictionary(key => key, value => (QueryLayer)null)); }
public IReadOnlyCollection <ResourceFieldAttribute> GetSparseFieldSetForQuery(ResourceContext resourceContext) { ArgumentGuard.NotNull(resourceContext, nameof(resourceContext)); if (!_visitedTable.ContainsKey(resourceContext)) { SparseFieldSetExpression inputExpression = _lazySourceTable.Value.ContainsKey(resourceContext) ? new SparseFieldSetExpression(_lazySourceTable.Value[resourceContext]) : null; SparseFieldSetExpression outputExpression = _resourceDefinitionAccessor.OnApplySparseFieldSet(resourceContext.ResourceType, inputExpression); HashSet <ResourceFieldAttribute> outputFields = outputExpression == null ? new HashSet <ResourceFieldAttribute>() : outputExpression.Fields.ToHashSet(); _visitedTable[resourceContext] = outputFields; } return(_visitedTable[resourceContext]); }
public IReadOnlyCollection <ResourceFieldAttribute> GetSparseFieldSetForQuery(ResourceContext resourceContext) { if (resourceContext == null) { throw new ArgumentNullException(nameof(resourceContext)); } if (!_visitedTable.ContainsKey(resourceContext)) { var inputExpression = _lazySourceTable.Value.ContainsKey(resourceContext) ? new SparseFieldSetExpression(_lazySourceTable.Value[resourceContext]) : null; var outputExpression = _resourceDefinitionAccessor.OnApplySparseFieldSet(resourceContext.ResourceType, inputExpression); var outputFields = outputExpression == null ? new HashSet <ResourceFieldAttribute>() : outputExpression.Fields.ToHashSet(); _visitedTable[resourceContext] = outputFields; } return(_visitedTable[resourceContext]); }
/// <inheritdoc /> public IReadOnlyCollection <AttrAttribute> GetAttributes(Type resourceType, RelationshipAttribute relationship = null) { if (resourceType == null) { throw new ArgumentNullException(nameof(resourceType)); } if (_request.Kind == EndpointKind.Relationship) { return(Array.Empty <AttrAttribute>()); } var sparseFieldSetAttributes = _constraintProviders .SelectMany(p => p.GetConstraints()) .Where(expressionInScope => relationship == null ? expressionInScope.Scope == null : expressionInScope.Scope != null && expressionInScope.Scope.Fields.Last().Equals(relationship)) .Select(expressionInScope => expressionInScope.Expression) .OfType <SparseFieldSetExpression>() .SelectMany(sparseFieldSet => sparseFieldSet.Attributes) .ToHashSet(); if (!sparseFieldSetAttributes.Any()) { sparseFieldSetAttributes = GetViewableAttributes(resourceType); } var inputExpression = sparseFieldSetAttributes.Any() ? new SparseFieldSetExpression(sparseFieldSetAttributes) : null; var outputExpression = _resourceDefinitionAccessor.OnApplySparseFieldSet(resourceType, inputExpression); if (outputExpression == null) { sparseFieldSetAttributes = GetViewableAttributes(resourceType); } else { sparseFieldSetAttributes.IntersectWith(outputExpression.Attributes); } return(sparseFieldSetAttributes); }