EF Core 'another instance is already being tracked'

前端 未结 4 819
情书的邮戳
情书的邮戳 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:39

    So, in the end we ended up using a custom UpdateEntity method to save our changes on some entities. This method goes through each property, navigation property and collection property of an entity, makes sure there is no chain and updates the objects a single time.

    It works for big objects and we only use it in those cases. For simple operations we keep using the simple Update

    Here is the link to a bitbucket repository with the source code

    In order to use this method, you will have to get the db entity first. Then call UpdateEntity method with the db entity and your entity received by the request.

    I hope it helps you as it helped me. Cheers!

提交回复
热议问题