Skip to content
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

Fixup navigations to/from join entity when new many-to-many relationship is created #26853

Merged
merged 3 commits into from
Dec 9, 2021

Conversation

ajcvickers
Copy link
Member

@ajcvickers ajcvickers commented Nov 30, 2021

Fixes #26779

Also cleanup of delay-fixup/suspended detection logic, and tests for #26074.

@ajcvickers ajcvickers requested a review from a team November 30, 2021 09:35
@ajcvickers
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ajcvickers
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ajcvickers ajcvickers marked this pull request as draft December 3, 2021 20:26
@ajcvickers ajcvickers removed the blocked label Dec 5, 2021
@ajcvickers ajcvickers marked this pull request as ready for review December 5, 2021 15:07
@ajcvickers ajcvickers changed the title Detach join entity when removing added relationship Fixup navigations to/from join entity when new many-to-many relationship is created Dec 5, 2021
{
if (_danglingJoinEntities != null)
var dangles = _danglingJoinEntities.ToList();
Copy link
Member

Choose a reason for hiding this comment

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

Why are you changing this? Is there a way that something could be added to _danglingJoinEntities during CompleteDelayedFixup()?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe so. However, BeginDelayedFixup can be called again, and we clear any existing danglers when this happens. This shouldn't be needed if everything is working correctly, but it is there against the possibility that some error happens when, for example, attaching the graph, and we leave the collection in a bad state. We could not do this, but it felt slightly more robust to keep doing it.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that this is more robust, but I'd prefer us to throw when an error happens rather than try to keep consistency.

You could throw in BeginDelayedFixup if _inAttachGraph is false and _danglingJoinEntities is not empty

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

You don't need to call ToList() anymore.

Also could avoid some allocations if you don't null-out _danglingJoinEntities

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it's better to keep the list around (even though it may not be used again, or not used for some time) rather than create a new one if we happen to need it again? (I've been wondering about this.)

Copy link
Member

Choose a reason for hiding this comment

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

I think that the chance of the list being used goes up significantly after it has been used once.

…hip is created

Fixes #26779

Also cleanup of delay-fixup/suspended detection logic, and tests for #26074.
- Throw if delayed fixup is left in an invalid state
- Store arguments rather than delegate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Many To Many Exception when adding and removing same entity
2 participants