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

ExecuteUpdate fails when target entity has an owned entity #28727

Closed
smitpatel opened this issue Aug 15, 2022 · 6 comments · Fixed by #29672 or #29723
Closed

ExecuteUpdate fails when target entity has an owned entity #28727

smitpatel opened this issue Aug 15, 2022 · 6 comments · Fixed by #29672 or #29723
Assignees
Labels
area-bulkcud closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Milestone

Comments

@smitpatel
Copy link
Member

No description provided.

@ajcvickers ajcvickers changed the title ExecuteUpdate/Delete on owned entity Test ExecuteUpdate/Delete on owned entity Aug 16, 2022
@ajcvickers ajcvickers added this to the MQ milestone Aug 16, 2022
@keatkeat87
Copy link

keatkeat87 commented Sep 26, 2022

image
I got this error when calling ExecuteDeleteAsync on a model having Owned Entity.
https://github.com/keatkeat87/EFCore7_ExecuteDeleteAsync

image

image

image

@ajcvickers
Copy link
Member

@keatkeat87 Please try with the daily build.

@Sebazzz
Copy link

Sebazzz commented Oct 18, 2022

I also got an issue with an entity that has owned entities, but I'm setting the property on the entity itself:

            await this._applicationDbContext.Sources
                      .Where(s => s.CopiedFromId == source.Id)
                      .ExecuteUpdateAsync(action => action.SetProperty(s => s.CopiedFrom, (Source) null), cancellationToken);

It goes wrong here because expression.Expression is an IncludeExpression instead of EntityShaperExpression:
image
image

This translation happens here, in the ReplacingExpressionVisitor:

image

@roji
Copy link
Member

roji commented Nov 25, 2022

This happens because the property selector lambda has an IncludeExpression wrapping the RelationalEntityShaperExpression.

To unblock use of ExecuteUpdate on non-owned properties, we can just unwrap the IncludeExpressions (there may be more than one); as long as after unwrapping, we get a PropertyExpression directly over RelationalEntityShaperExpression, things should work fine. I will do this in #29672, which is very similar, allowing interface up-casts in update property selectors.

However, allowing ExecuteUpdate to reference owned properties is another matter (i.e. with table sharing, or possibly JSON - see #28766), and more complex. We should split that out to another issue.

@roji roji changed the title ExecuteUpdate/Delete fails when target entity has an owned entity ExecuteUpdate fails when target entity has an owned entity Nov 25, 2022
@roji roji modified the milestones: Backlog, 8.0.0 Nov 25, 2022
roji added a commit to roji/efcore that referenced this issue Nov 25, 2022
Referencing unowned properties only for now.

Fixes dotnet#28727
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 25, 2022
@roji
Copy link
Member

roji commented Nov 25, 2022

Allowing referencing owned properties in the property selector is covered by #28627.

roji added a commit to roji/efcore that referenced this issue Nov 26, 2022
Referencing unowned properties only for now.

Fixes dotnet#28727
roji added a commit that referenced this issue Nov 30, 2022
@roji roji removed this from the 8.0.0 milestone Nov 30, 2022
@roji
Copy link
Member

roji commented Nov 30, 2022

Clearing milestone to discuss patching

@roji roji reopened this Nov 30, 2022
roji added a commit to roji/efcore that referenced this issue Dec 1, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.x, 7.0.3 Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-bulkcud closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Projects
None yet
5 participants