用UnitOfWork进行实体更新的时候,再查询实体一次,再去更新的时候会报如下错误:

Attaching an entity of type 'TinyFrame.Data.DomainModel.t_user_application' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate.

解决办法如下:

    public virtual async Task<T> GetOne(Expression<Func<T,bool>> where) {
return await _dbSet.Where(where).AsNoTracking().FirstOrDefaultAsync();
}

用AsNoTracking不进行跟踪,就可以更新了

记录下

UnitOfWork 更新实体出错解决办法的更多相关文章

  1. svn更新路径,解决办法详细步骤,eclipse里面的更新方法,svn废弃位置,Windows环境,svn服务器地址换了,如何更新本地工作目录

    svn更新路径,解决办法详细步骤,eclipse里面的更新方法,svn废弃位置,Windows环境,svn服务器地址换了,如何更新本地工作目录 Windows下,svn服务器IP本来是内网一台服务器上 ...

  2. 黄聪:C#使用Application.Restart重启程序出错解决办法

    调用 Application.Restart重启程序出错 解决办法,就是给程序的.exe文件,加上下面的设置

  3. npm中npm install 始终出错解决办法

    npm中npm install 始终出错解决办法 错误信息: C:\Windows\System32>npm install -g gulp npm ERR! Windows_NT 6.1.76 ...

  4. IObit Driver Booster 无法更新驱动的解决办法

    IObit Driver Booster 无法更新驱动的解决办法:依次打开软件中的 菜单-设置-网络-自定义代理设置-主机:填入210.101.131.231 端口:8080 最后点确定完成. 注意! ...

  5. ARM64平台编译stream、netperf出错解决办法 解决办法:指定编译平台为alpha [root@localhost netperf-2.6.0]# ./configure –build=alpha

    ARM64平台编译stream.netperf出错解决办法 http://ilinuxkernel.com/?p=1738 stream编译出错信息: [root@localhost stream]# ...

  6. dpkg:处理 xxx (--configure)时出错解决办法,也可用于卸载软件出错的情况

    dpkg:处理 xxx (--configure)时出错解决办法今早安装nfs时出现问题,找到该文,备份留用.然后在网上找到了这片文章,按步骤走就解决了,中间会提示自动卸载一下,执行那个命令就好了,我 ...

  7. youtube-dl更新出错解决办法

    youtube-dl更新命令: youtube-dl -U 更新报错:无法识别当前版本 ERROR: can't find the current version. Please try again ...

  8. ORBSLAM2与OPENCV3.1.0出错解决办法

    用opencv3.1.0做ORBSLAM2运行一下命令时cd ORB_SLAM2 chmod +x build.sh ./build.sh出错:/usr/bin/ld: CMakeFiles/mono ...

  9. Win10更新补丁失败后出现无法更新正在撤销 解决办法

    系统更新失败,反复重启还是不行,那是不是下载下来的补丁没用了呢??所以我们先要删除Windows更新的缓存文件!在做以下操作之前,首先我们要确认系统内的windows update & BIT ...

随机推荐

  1. 临时文件夹迁移 temp位置移动

    方法/步骤 首先,在其他驱动器新建一个文件夹,给临时文件夹安个新家 桌面,右键"我的电脑",选择"属性" 点击"高级系统设置" 点击&quo ...

  2. Extjs4.x 共享组件,写法

    1.项目架构如下: /Application /ext--框架核心文件 /common--共享 /resources--共享资源 /src--共享js(例如,多个模块共享一个store等) /mode ...

  3. mysql show global variables字符超1024会被截断

    show variables 会存在数据被截断的问题: select 全局变量没有问题 官网解释:https://dev.mysql.com/doc/refman/5.6/en/variables-t ...

  4. 从商业角度探讨API设计

    为Web设计.实现和维护API不仅仅是一项挑战:对很多公司来说,这是一项势在必行的任务.本系列将带领读者走过一段旅程,从为API确定业务用例到设计方法论,解决实现难题,并从长远的角度看待在Web上维护 ...

  5. 【oneday_onepage】——The Secret Of Steve<1>

    The Secret Of SteveThe secret of Steve is simple. It explains his success and excess. It exemplifies ...

  6. 安装redis出现cc adlist.o /bin/sh:1:cc:not found

    安装redis时 提示执行make命令时, 提示 CC adlist.o /bin/sh: cc: 未找到命令 问题原因:这是由于系统没有安装gcc环境,因此在进行编译时才会出现上面提示,当安装好gc ...

  7. SpringBoot2 全局异常处理

    参考这篇文章里面的几种异常形式: 全局异常处理是个比较重要的功能,一般在项目里都会用到. 大概把一次请求分成三个阶段,来分别进行全局的异常处理. 一:在进入Controller之前,譬如请求一个不存在 ...

  8. PCL中点云数据格式之间的转化

    (1) 关于pcl::PCLPointCloud2::Ptr和pcl::PointCloud<pcl::PointXYZ>两中数据结构的区别 pcl::PointXYZ::PointXYZ ...

  9. Hibernate执行原生SQL

    1.查询指定字段 public List<Object[]> getUseList( Integer index, Integer offset, String state, String ...

  10. 获取checkbox的选中的值

    var arr = new Array(); var idsObj = $("input [name='ids']"); for(var i=0;i<idsObj.lengt ...