Hi, @Reema George Dass. Welcome to Microsoft Q&A.
I am using version 8.0.0 of Entity Framework Core
. In my test, the code you provided could be added correctly and is not added twice by mistake.
Please do the following test:
1.Assuming that you are using a database in Visual Studio 2022 and have turned off the auto-increment of the primary key in the table (here is Identity
).
Then when you execute the
AddAsync
method, the entity
passed in must specify the Id
.
YourEntity entity = new YourEntity() { Id = 1, Name = "AA" };
2.Suppose you have turned on the auto-increment of the primary key in the table.
Then when you execute the AddAsync
method, the entity passed in should not specify the Id
.
YourEntity entity = new YourEntity() { Name = "AA" };
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.