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

前端 未结 6 2211
日久生厌
日久生厌 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:40

    I was getting the same problem when was trying to update the value. then i found the proble i was using this.

    services.AddDbContext(option => option.UseSqlServer(Configuration.GetConnectionString("databasename")),ServiceLifetime.Singleton);
    

    then i remove lifetime and it worked well for me.

    services.AddDbContext(option => option.UseSqlServer(Configuration.GetConnectionString("databasename")));
    

提交回复
热议问题