Skip to content

Adding extra includes from IResourceDefinition.OnApplyIncludes() does not work #989

Closed
@bart-degreed

Description

@bart-degreed

Example:

public sealed class Engagement : EntityBase<Guid>
{
    [HasMany]
    public ICollection<EngagementParty> Parties { get; set; }
}

public sealed class EngagementParty : EntityBase<Guid>
{
}

public sealed class EngagementResourceDefinition : JsonApiResourceDefinition<Engagement, Guid>
{
    public EngagementResourceDefinition(IResourceGraph resourceGraph)
        : base(resourceGraph)
    {
    }

    public override IReadOnlyCollection<IncludeElementExpression> OnApplyIncludes(
        IReadOnlyCollection<IncludeElementExpression> existingIncludes)
    {
        ResourceContext engagementContext = ResourceGraph.GetResourceContext<Engagement>();

        RelationshipAttribute partiesRelationship = engagementContext.Relationships.Single(relationship
            => relationship.Property.Name == nameof(Engagement.Parties));

        HashSet<IncludeElementExpression> newIncludes = existingIncludes.ToHashSet();
        newIncludes.Add(new IncludeElementExpression(partiesRelationship));
        return newIncludes;
    }
}

The query gets composed and executed properly, but the serializer forgets to take additions from IResourceDefition<,>.OnApplyIncludes into account.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions