EF Core 保存导航属性报错 insert_Identify 验证问题 The instance of entity type ‘name‘ cannot be tracked

news/2024/5/19 21:48:39 标签: .netcore

错误1:The instance of entity type ‘name’ 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.

错误2 insert_Identify 验证问题

可能原因为:同一个entity存在被多个context标记为add
1、获取了多个context对象,在netcore一般用同一个context,不要随意的去容器中取,如果没设置好,可能会导致多个context instance同时操作track EF
2、对顶层的entityEntry设置add状态,然后在导航属性又设置一遍

解决方案: 对症下药


http://www.niftyadmin.cn/n/1418203.html

相关文章

去除重复列(awk之数组妙用)

说明&#xff1a;蓝色命令名称 浅绿命令参数 浅蓝选项 紫色目录 系统环境&#xff1a;CentOS 6.2 i686 有文件&#xff0c;包含的内容如下&#xff1a; 去除重复列结果如下&#xff1a; 方法&#xff1a;awk {for(i1;i<NF;i)a[$i,NR]}{for(j in a){split(j,b,SUBSEP);if(b…

EC Core FromSql 查询返回自定义entity

利用EF FromSql 自定义查询&#xff0c;有时间须要的字段可能是自定义的&#xff0c;因此须要返回自定义类的list 一、System.Data.Common /// <summary>/// EF query by sql/// </summary>/// <param name"context"></param>/// <param…

ActionForm中的表单跨页

<?xml version"1.0" encoding"UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"…

nodejs 代理 https : DEPTH_ZERO_SELF_SIGNED_CERT

1、NodeJS 测试开发时一般用http地址&#xff0c;不用https&#xff0c;会出现证书问题DEPTH_ZERO_SELF_SIGNED_CERT 2、如果非得使用https, 则须要安装证书

聊聊.net程序设计——浅谈使用VS2010建模拓展(续)[转]

最近公司有2个项目将要上线&#xff0c;所以一直在加班&#xff08;行业的潜规则&#xff09;一直也没有时间写些自己感兴趣的东西&#xff0c;今天正好偷懒了没有加班提前回家&#xff0c;想着将前些时候写的《聊聊.net程序设计——浅谈使用VS2010建模拓展&#xff08;下&…

axios发送请求获取reponse header中的数据问题

如果是自定义的header名称&#xff0c;须要在跨域中设置&#xff1a;.WithExposedHeaders(“X-Total-Count”) services.AddCors(options >{options.AddPolicy("AllowAllOrigin", builder >{builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().Allow…

简单设置windows server 2008

关闭IE SEC   服务器系统要求很高的安全性&#xff0c;所以微软给ie添加了安全增强。这就使得ie在Internet区域的安全级别一直是最高的&#xff0c;而且无法进行整体调整。   点击快速运行栏的“服务器管理器”&#xff0c;开启服务器管理器。 1.勾选“登录时不要显示此…

EF Core DateTime 时间类型 查找 问题

EF Core 在时间查询时须要注意毫秒问题 1、如果数据库存储带了毫秒&#xff0c;那么在查询的时候传参也要带毫秒 --WorkDate字段没有毫秒的情况 StudioGeneric.Set<table1>().Where(p > p.WorkDate > new DateTime(2022, 6, 1, 23, 59, 59));2、如果数据库存储没…