The instance of entity type 'Item' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked

前端 未结 6 2220
日久生厌
日久生厌 2021-02-14 13:21

I am aware that such question has already been asked, but solution did not help me.

[Fact]
public async Task UpdateAsync()
{
    string newTitle = \"newTitle1\";         


        
6条回答
  •  心在旅途
    2021-02-14 13:44

    I had same problem while I was copying some records in database by Entity Framework and changing one column that was other's entity key. Tracking mode change did not fix the issue.

    The issue was fixed by properly setting primary key in EntityTypeConfiguration, to contain the changed value here described as x.EntityTwoKey.

    builder.HasKey(x => new { x.EntityOneKey, x.EntityTwoKey });
    

提交回复
热议问题