EF Core 'another instance is already being tracked'

前端 未结 4 861
情书的邮戳
情书的邮戳 2021-01-11 18:30

I have a problem updating an entity in .Net Core 2.2.0 using EF Core 2.2.3.

An error occurred while saving changes. Error details: The instance of

4条回答
  •  无人及你
    2021-01-11 18:45

    I had the same issue but trying to add a second row to the same Entiy. In my case it was because I was assuming the primary key was an Int Identity and auto-generated. As I wasn't assigning any value to it, the second row had the same Id, which is cero default. Lesson learned, when you see this error during an Add() operation in EF, make sure your key is IDENTITY if that's your intention.

提交回复
热议问题