locked
Is It Bug of Entity Framework? RRS feed

  • Question

  • "Object with the same key already exists in the ObjectStateManager" this type error will come when i want to update a particular table row with using AsNoTracking().With out use AsNoTracking() I can update table row.Why This kind of error will come when i user AsNoTracking() method?Is it bug of entity framework?

    Monday, July 9, 2018 6:09 AM

All replies

  • Hi ssubhankar,

    From this article, we can saw that there are significant performance gains to be obtained by using the AsNoTrack method. We can get better performance with a Snapshot tracker compared to a proxy tracker. We should use this method with queries in which we do not want to save the data back to the database.

    https://www.c-sharpcorner.com/UploadFile/ff2f08/entity-framework-and-asnotracking/

    When you use asNoTracking() you get an unconnected entity that cannot be updated normally with EntityState.Modified. Then, one trick is to replace the cached entity values with non-cached entity values.

    https://stackoverflow.com/questions/13693757/entity-framework-error-with-asnotracking-and-objectstatemanager

    So, if you want to save the data back to the database, you could not using AsNoTracking.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 9, 2018 8:07 AM