Bug description
When using ExecuteUpdate with a provided open SqlConnection and creating an empty entity (an entity with only the id property with auto increment) before calling ExecuteUpdate the result of ExecuteUpdate is -1
Just to summarize, the following is required for the bug:
- A DbContext created with an open
SqlConnection
- Creation of an entity with no properties being set before calling
ExecuteUpdate
Notice in the trace.sql in the gist that the insert for the empty entity is not wrapped in sp_executesql. This causes the SET NOCOUNT ON; to affected the ExecuteUpdate query. If the insert was wrapped in sp_executesql this would not be a problem, like the insert for the more entity with the name field.
Your code
https://gist.github.com/frederikrosenberg/74362389151aec5a4e54e7b1376be390
EF Core version
9.0.10
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
NET 9
Operating system
Windows 11
IDE
Rider 2025.2