Skip to content

GetAffected syntax in resource hook helpers #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 18, 2019

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.

2 participants