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

What's new for ExecuteUpdate and ExecuteDelete #3982

Merged
merged 5 commits into from
Aug 17, 2022
Merged

Conversation

ajcvickers
Copy link
Member

No description provided.

@ajcvickers ajcvickers requested a review from a team August 16, 2022 10:59
entity-framework/core/what-is-new/ef-core-7.0/whatsnew.md Outdated Show resolved Hide resolved
entity-framework/core/what-is-new/ef-core-7.0/whatsnew.md Outdated Show resolved Hide resolved
await context.Posts
.Where(p => p.PublishedOn.Year < 2022)
.ExecuteUpdateAsync(
s => s.SetProperty(b => b.Title, b => b.Title + " (" + b.PublishedOn.Year + ")")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe indent so that the SetProperty's are aligned

> Microsoft.Data.SqlClient.SqlException (0x80131904): The DELETE statement conflicted with the REFERENCE constraint "FK_Posts_Authors_AuthorId". The conflict occurred in database "TphBlogsContext", table "dbo.Posts", column 'AuthorId'.
The statement has been terminated.

To fix this, we must first either delete the posts, or sever the relationship between each post and its author by setting `AuthorId` foreign key property to null. For example, using the delete option:
Copy link
Member

Choose a reason for hiding this comment

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

I'd put the database cascading delete solution first, since it's really the thing to do wheter supported. Honestly, that's the universal relational way to do this, and this whole complexity is only because SQL Server doesn't support cycles... Like in PG I'd always recommend cascade deletes...

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'd rather leave it the way it is, because talking about the problem first shows why cascades are useful.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense!

entity-framework/core/what-is-new/ef-core-7.0/whatsnew.md Outdated Show resolved Hide resolved
@ajcvickers ajcvickers merged commit 9abe33c into main Aug 17, 2022
@roji roji deleted the OffWithHerHead0814 branch August 17, 2022 11:46
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.

2 participants