Skip to content

Conversation

@maurei
Copy link
Member

@maurei maurei commented Jul 14, 2019

This PR adds some functionality to RelationshipDictionary<T> and DiffableEntityHashSet<T>: the GetAffected<T>(Func<T, object>) method. This method enables it to resolve the entities which have an updated value for the property as reflected in the navigation expression, similar to EF Core's Include( (a) => ( a.b)). This works for both relationships and members of the model itself.

Usage is like this:

public override IEnumerable<Article> BeforeUpdate(IDiffableEntityHashSet<Article> entities, ResourcePipeline pipeline)
{
    // gets the articles for which the `Author` relationship was updated.
    HashSet<Article> affectedByAuthor = entities.GetAffected( a => a.Author);

    // gets the articles for which the `Title` attribute was updated.
    HashSet<Article> affectedByTitle = entities.GetAffected( a => a.Title);

   // do some stuff with `affectedByAuthor` and/or `affectedByTitle`.

    return entities
}

This PR depends PR #538 to be merged first

@maurei maurei requested a review from wisepotato July 14, 2019 17:29
@maurei maurei changed the title [ResourceHooks] GetAffected syntax in resource hook helpers GetAffected syntax in resource hook helpers Jul 15, 2019
@wisepotato wisepotato self-requested a review July 18, 2019 07:12
@wisepotato wisepotato merged commit c6762b3 into master Jul 18, 2019
@maurei maurei deleted the feat/fluent-get-affected branch July 18, 2019 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants