efcore icon indicating copy to clipboard operation
efcore copied to clipboard

why does remove Non-existent entity throw an exception

Open 312527814 opened this issue 7 years ago • 1 comments

when remove Non-existent entity EF Core will throw Database operation expected to affect 1 row(s) but actually affected 0 row(s) exception. in the Source code i find the Method:

 protected virtual int ConsumeResultSetWithoutPropagation(int commandIndex, [NotNull] RelationalDataReader reader)
        {
            var expectedRowsAffected = 1;
            while (++commandIndex < CommandResultSet.Count
                   && CommandResultSet[commandIndex - 1] == ResultSetMapping.NotLastInResultSet)
            {
                Debug.Assert(!ModificationCommands[commandIndex].RequiresResultPropagation);

                expectedRowsAffected++;
            }

            if (reader.Read())
            {
                var rowsAffected = reader.DbDataReader.GetInt32(0);
                if (rowsAffected != expectedRowsAffected)
                {
                    ThrowAggregateUpdateConcurrencyException(commandIndex, expectedRowsAffected, rowsAffected);
                }
            }
            else
            {
                ThrowAggregateUpdateConcurrencyException(commandIndex, 1, 0);
            }

            return commandIndex;
        }

in the method if rowsAffected != expectedRowsAffected it will throw ThrowAggregateUpdateConcurrencyException. I want to know why must throw exception when rowsAffected != expectedRowsAffected. some time i don't care remove result ,but because of the exception i must Handle the remove result,otherwise my application can't runing.

312527814 avatar Jul 25 '19 09:07 312527814

@312527814 See #10443

ajcvickers avatar Jul 25 '19 18:07 ajcvickers