D
D
DenisVladimirovich2019-09-02 21:55:04
ASP.NET
DenisVladimirovich, 2019-09-02 21:55:04

Why is the wrong ID inserted in EFCore?

Good evening. Again I write a question, because no one let me know the reason for that.
Up to a certain point, everything goes fine. But then out of nowhere, even if you set the value to 0 in advance, it exits because on the image
5d6d6340157bb185188216.png
The program crashes with the error "Cannot insert an explicit value for the identity column in the table \"Deals\" when the IDENTITY_INSERT parameter is OFF."
The code for pastbin
48 is an ID, which should generally be equal to zero, and the second 48 should be -2 plus million

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-09-02
@DenisVladimirovich

Before line 213 put

db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Deals ON");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question