-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
InvalidOperationException when calling ExecuteUpdate with owned entity & using current value #30528
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
Minimal repro with 7.0.4: await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
ctx.Entities.ExecuteUpdate(updates => updates.SetProperty(e => e.Name, e => e.Name));
class BlogContext : DbContext
{
public DbSet<Blog> Entities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
public BlogDetails Owned { get; set; }
}
[Owned]
public class BlogDetails
{
public string Value { get; set; }
} Exception:
|
This works: await context.Entities.ExecuteUpdateAsync(x => x.SetProperty(e => e.Name, "X")); And this works: var newVal = "X";
await context.Entities.ExecuteUpdateAsync(x => x.SetProperty(e => e.Name, newVal)); But this throws: await context.Entities.ExecuteUpdateAsync(x => x.SetProperty(e => e.Name, e => e.Name)); |
@ajcvickers thanks, I'll look into this soon. I may have a hunch. |
roji
added a commit
to roji/efcore
that referenced
this issue
Mar 24, 2023
Submitted #30571, definitely a good candidate for patching. |
roji
added a commit
to roji/efcore
that referenced
this issue
Mar 24, 2023
roji
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Mar 24, 2023
roji
added a commit
that referenced
this issue
Mar 25, 2023
roji
added a commit
to roji/efcore
that referenced
this issue
Mar 25, 2023
* Fully prune IncludeExpression before ExecuteUpdate, not just for the property lambda * Prune also non-owned Includes Fixes dotnet#30572 Fixes dotnet#30528 (cherry picked from commit 4c6f854)
roji
added a commit
to roji/efcore
that referenced
this issue
Nov 17, 2023
* Fully prune IncludeExpression before ExecuteUpdate, not just for the property lambda * Prune also non-owned Includes Fixes dotnet#30572 Fixes dotnet#30528 (cherry picked from commit 4c6f854)
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
When calling ExecuteUpdate to conditionnaly update an entity with owned subentity, an
System.InvalidOperationException
is thrown.Repro code here: https://github.com/mgrosperrin/repro_issues/tree/efcore-executeupdate-owned-entity
My goal is to update the property only if the user provide a value and to use the current value otherwise (to response to a PATCH API call).
The code in the repo use the null coalescing operator, but I have the same exception with the following code:
updates.SetProperty(e => e.Name, e => e.Name)
Include stack traces
Include the full exception message and stack trace for any exception you encounter.
Use triple-tick fences for stack traces. For example:
Include provider and version information
EF Core version: 7.0.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.5.2
The text was updated successfully, but these errors were encountered: