Skip to content

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

Merged
ajcvickers merged 3 commits into
mainfrom
AddorNot1128
Dec 9, 2021
Merged

ajcvickers merged 3 commits into
mainfrom
AddorNot1128

Conversation

@ajcvickers

@ajcvickers ajcvickers commented Nov 30, 2021 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@ajcvickers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
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)
{
if (_danglingJoinEntities != null)
var dangles = _danglingJoinEntities.ToList();

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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.

Comment thread src/EFCore/ChangeTracking/Internal/NavigationFixer.cs Outdated
…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