dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.53k stars 3.13k forks source link

Delete statements to SQL Server do not raise exceptions when delete statement fails #8949

Closed SergeyBarskiy closed 1 year ago

SergeyBarskiy commented 7 years ago

Describe what is not working as expected. If I flag a row as delete and call save change, an error that is raised in SQL Server is not propagated to .NET run time

Steps to reproduce

Create a row that has related data. Try to delete this row using EF core by flagging an entity as deleted. Here is the statement generated: exec sp_executesql N'SET NOCOUNT ON; DELETE FROM [Contacts].[People] WHERE [PersonId] = @p0; SELECT @@ROWCOUNT;

',N'@p0 int',@p0=3

Here is the error raised in SQL Server if I execute the same in SSMS Msg 547, Level 16, State 0, Line 2 The DELETE statement conflicted with the REFERENCE constraint "FK_COMPANYPERSON_PERSON". The conflict occurred in database "ContactsDatabase", table "Contacts.CompanyPersons", column 'PersonId'. The statement has been terminated.

However, 0 is still select as part of select @@rowcount At this point an error should be raised in EF core, but it is not.

EF Core version: 2.0 preview 1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 IDE: Visual Studio 2017

SergeyBarskiy commented 7 years ago

I had async in it accidentally