Skip to content

fix(#343): reload relationships from database if included during POST #373

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 4 commits into from
Aug 11, 2018

Conversation

jaredcnance
Copy link
Contributor

@jaredcnance jaredcnance commented Aug 10, 2018

Closes #343

BUG FIX

  • reproduce issue in tests
  • fix issue
  • bump package version

Verified solution results in only two queries regardless of number of included relationships:

image

{
foreach (var hasManyPointer in pointers)
{
await _context.Entry(hasManyPointer).ReloadAsync();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is bad ☹️ ... need to reload the entire navigation property

Copy link
Contributor

@milosloub milosloub Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all. Thank you, for this solution.
For HasMany relationships, what about something like:
_context.Entry(entity).Collection(relation).Load();

instead of:
_context.Entry(hasManyPointer).ReloadAsync();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I wasn't aware of the .Collection api. I think I like the approach I ended up taking better. The reason is that we should end up with a single SQL request that uses JOIN to load all the relationships rather than reloading each included relationship individually. I'll review it again later tonight to verify the difference.

@jaredcnance jaredcnance merged commit c33c455 into master Aug 11, 2018
@jaredcnance jaredcnance deleted the fix/#343 branch August 11, 2018 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[2.4.0-beta1]: POST with self referencing inclusion returns null values (or default) in included entity
2 participants