风轻云淡

-------生活没有抱怨,只有自己的不努力,当才华撑不起梦想与野心,不断学习是你唯一的选择。没有伞的孩子必须努力奔跑...

导航

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

EF Core 修改实例报错:==》》

System.InvalidOperationException: The instance of entity type 'ProductInfo' 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.
 

解决方法:

services.AddDbContext<DbContext, LTWMSDaoMysql.EFModel.LTWMSContext>(c=>c.UseMySQL(Configuration.GetConnectionString("mysqlcon")).UseQueryTrackingBehavior( QueryTrackingBehavior.NoTracking));

posted on 2020-03-17 15:42  淡然→笑  阅读(1597)  评论(0编辑  收藏  举报