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

why does remove Non-existent entity throw an exception #16741

Closed
312527814 opened this issue Jul 25, 2019 · 1 comment
Closed

why does remove Non-existent entity throw an exception #16741

312527814 opened this issue Jul 25, 2019 · 1 comment

Comments

@312527814
Copy link

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.

@ajcvickers
Copy link
Member

@312527814 See #10443

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants