AsNoTracki或者全局禁用

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// 关闭EF Core默认追踪
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);

optionsBuilder.EnableDetailedErrors();
}

EF Corexxxxnstance with the same key value for {'Id'} is already being tracked.的更多相关文章

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

    这里记录一个在使用.net core中ef core执行数据库操作时遇到的问题: 我在代码中使用DbContext下的Update方法准备将更改后的数据像这样步到数据库: _context.Menus ...

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

    一.问题描述 问题:The instance of entity type 'xxxx' cannot be tracked because another instance with the sam ...

  3. The instance of entity type 'manager' 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 ent

    最近在用ASP.NET CORE时遇到一些问题,现记录下: 出现上述错误,即在更新实体数据时出现的错误 services.AddDbContext<StoreContext>(c => ...

  4. entity cannot be tracked

    背景:EF Core项目中使用InMemory作为数据库提供程序,编写单元测试. 报错:“The instance of entity type 'Movie' cannot be tracked b ...

  5. 【WPF】EntityframeworkCore Update注意事项

    The instance of entity type 'Book' cannot be tracked because another instance with the same key valu ...

  6. 9.3 翻译系列:数据注解特性之Key【EF 6 Code-First 系列】

    原文链接:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.a ...

  7. EF Core中Key属性相同的实体只能被跟踪(track)一次

    在EF Core的DbContext中,我们可以通过DbContext或DbSet的Attach方法,来让DbContext上下文来跟踪(track)一个实体对象,假设现在我们有User实体对象,其U ...

  8. .NetCore之EF跳过的坑

    我在网上看到很多.netCore的信息,就动手自己写一个例子测试哈,但是想不到其中这么多坑: 1.首先.netCore和EF的安装就不用多说了,网上有很多的讲解可以跟着一步一步的下载和安装,但是需要注 ...

  9. EF使用CodeFirst方式生成数据库&技巧经验

    前言 EF已经发布很久了,也有越来越多的人在使用EF.如果你已经能够非常熟练的使用EF的功能,那么就不需要看了.本文意在将自己使用EF的方式记录下来备忘,也是为了给刚刚入门的同学一些指导.看完此文,你 ...

  10. EntityFramework之摸索EF底层(八)

    前言 此篇文章我将深入去摸索edmx中一些不为人知的东西,有时候我们需要知道Code  First模型中一些存储以及映射的原理,个人觉得那是必要的也是有用的,因为很有可能SQL会出现一些其他问题,只有 ...

随机推荐

  1. 使用 BenchmarkDotNet 比较指定容量的 List 的性能

    我们之前提到 List 是 .NET 中常用的数据结构,其在存储大量数据时,如果能够指定它的初始化容量,就会有性能提升.这个优化的方法并不是很明显,因此本文将使用 BenchmarkDotNet 库, ...

  2. 外包公司中的"炼狱",极度摧残,避免踩坑。

    引言 前些天羊了,一直没有更新.今天给大家聊聊两家外包公司,遇到的小伙伴避免踩坑. 咱不说那些虚的,什么尽量不要去外包公司,尽可能找甲方,这些谁都知道,肯定是因为一些原因(比如学历.项目经验.技术有待 ...

  3. 手写Pinia存储的数据持久化插件

    Pinia和Vuex的通病 Pinia和vuex的通病就是,页面刷新会导致数据丢失 解决通病 一.新建store import { defineStore } from 'pinia' //单独存放S ...

  4. 【随笔】Ubuntu18.04下virtualbox卡死的解决办法

    //得到该进程ID X pgrep Xorg //杀掉进程 kill X 然后重新登陆帐号即可

  5. Android Volley 基本使用

    Android Volley 基本使用 本篇主要介绍 Google 给Android 平台提供的 Volley 一个 Http请求库 , 齐射! 1.概述 Volley是Google 提供的一个小巧的 ...

  6. (9)go-micro微服务Redis配置

    目录 一 go-redis介绍 二 go-redis安装 三 redis初始化连接 四 存储mail邮件 五 存储token 六 最后 一 go-redis介绍 Redis(Remote Dictio ...

  7. 洛谷P6599 「EZEC-2」异或【题解】

    题目大意 有\(T\)组数据,每组数据给定两个\(l,n\in\mathbb{N*}\),构造一个长为\(l\),每个元素不超过\(n\)的数组 令他为\(a\),要使 \[\sum_{i=1}^l\ ...

  8. python读取kafka,输出到Vertica数据库

    # 主测试 # https://docs.python.org/2/library/json.html import sys import json import vertica_python imp ...

  9. css边框,盒子模型、浮动、定位

    边框,盒子模型.浮动.定位 一.边框 border-width : 边框宽度 border-style : 边框样式 1.solid 实线 2.none 无边框 3.dotted 点状虚线边框 4.d ...

  10. windows消息处理机制

    三层机制 1.顶端就是Windows内核.Windows内核维护着一个消息队列,第二级控制中心从这个消息队列中获取属于自己管辖的消息,后做出处理,有些消息直接处理掉,有些还要发送给下一级窗体(Wind ...