You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating methods for registering users with a default role. I found that if the options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) option is enabled, an exception occurs when adding a role to a user.
"System.InvalidOperationException: 'The instance of entity type 'User' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.'"
As soon as I turn off QueryTrackingBehavior.NoTracking, the method works without problems.
The service where NoTracking works is not small, and I did not want to turn it off option.
Is it possible to fix this?
If not, it would be nice to add text to the exception that would help to understand the problem. I spent a day to understand what the reason was, since I added authentication using lessons/reports by other authors, and each time it led to a stupor when everything works out in the author's lesson, and I have an exception
The text was updated successfully, but these errors were encountered:
I am creating methods for registering users with a default role. I found that if the options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) option is enabled, an exception occurs when adding a role to a user.
"System.InvalidOperationException: 'The instance of entity type 'User' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.'"
As soon as I turn off QueryTrackingBehavior.NoTracking, the method works without problems.
The service where NoTracking works is not small, and I did not want to turn it off option.
Is it possible to fix this?
If not, it would be nice to add text to the exception that would help to understand the problem. I spent a day to understand what the reason was, since I added authentication using lessons/reports by other authors, and each time it led to a stupor when everything works out in the author's lesson, and I have an exception
The text was updated successfully, but these errors were encountered: