- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在两个表中插入记录,但出现异常。您能帮我解决这个问题吗?
首先我尝试了下面的代码。
await _testRepository.InsertAsync(test);
await _xyzRepository.InsertAsync(xyz);
然后我尝试了这段代码,但没有任何效果。
try
{
var test = new Test();
using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
{
int? tenantId = _unitOfWorkManager.Current.GetTenantId();
using (_unitOfWorkManager.Current.SetTenantId(tenantId))
{
await _testRepository.InsertAsync(test);
var xyz = new XYZ();
await _xyzRepository.InsertAsync(xyz);
await _unitOfWorkManager.Current.SaveChangesAsync();
await uow.CompleteAsync();
}
}
}
catch (Exception ex)
{
throw new UserFriendlyException(ex.Message);
}
异常
消息:
Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
堆栈跟踪:
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(Int32 commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected) at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.d__7`2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.d__61.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.d__59.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.DbContext.d__48.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.EntityFrameworkCore.AbpDbContext.d__49.MoveNext() in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\AbpDbContext.cs:line 214
INFO 2018-04-11 13:59:53,439 [3 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method MyCompany.MyProject.AdditionalMasterData.Tests.TestsAppService.CreateOrEdit (MyCompany.MyProject.Application) with arguments ([CreateOrEditTestDto ]) - ModelState is Valid WARN 2018-04-11 14:01:48,396 [4 ] Mvc.ExceptionHandling.AbpExceptionFilter - Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions. Abp.UI.UserFriendlyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions. at MyCompany.MyProject.AdditionalMasterData.Tests.TestsAppService.d__7.MoveNext() in C:\Repo\MyProjectVenues\aspnet-core\src\MyCompany.MyProject.Application\AdditionalMasterData\Tests\TestsAppService.cs:line 205 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MyCompany.MyProject.AdditionalMasterData.Tests.TestsAppService.d__6.MoveNext() in C:\Repo\MyProjectVenues\aspnet-core\src\MyCompany.MyProject.Application\AdditionalMasterData\Tests\TestsAppService.cs:line 170 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__23.MoveNext()
更新
我已经找到了问题的根本原因。
所以基本上我在 Entity2 上有一个插入触发器,当我在这个触发器内评论查询时,它就可以正常工作了。
此触发器中有大约 10 个查询,很难知道哪一个查询导致了问题。那么您能告诉我如何调试这个触发器吗?
最佳答案
我也遇到了类似的问题。我用的是 EF Core。我的代码的以下更改对我有所帮助。
context.Entry(user).State = EntityState.Added; // added row
this.context.Users.Add(user);
this.context.SaveChanges();
UPD:抱歉,问题已通过为 User.Id 添加 Identity 属性得到解决
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
关于c# - 数据库操作预计影响 1 行,但实际影响 0 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49781548/
我目前正在使用协卷积层来训练神经网络,但在向其提供输入和输出维度时似乎存在一些问题。 输入由 (x,2050) 组成输出为 (x,13)因此,对于每行 2050 列,应创建一个包含 13 个元素的数组
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我有以下内容: public String searchRecipes( String searchString, int pageNumber ) throws Exception {
现在,在任何人链接这篇文章之前: JSLint : Expected '!!' and instead saw '?' 我想解释一下,我想我明白为什么 jslint 给我这个错误,但是我不确定如何修改
我正在尝试远程登录到 Cisco 路由器并使用 pexpect 发出命令。它的工作,但 sendline() 在输出中重复。即使在使用 setecho 为 False 之后。代码是: ''' Crea
我写了一个脚本从vsql中选择: LOAD 'sql://{select * from sandesh.insights_voice_day WHERE Observation_date BE
这个问题在这里已经有了答案: Android - How to achieve setOnClickListener in Kotlin? (32 个回答) 去年关闭。 我正在尝试使此切换按钮起作用-
我想在两个类之间传递一个值,但出现以下错误: Syntax error on token ";", , expected when initializing called value from ano
我使用 MySQL 5.5 ,我的表有 6 列,数据类型为 int 、varchar 、datetime 。我为 Id (int) 列创建索引。如果我希望基于 Id 列的条件查询始终保持响应时间低于
你好社区我正在做一个简单的应用程序,用户可以注册(作为新用户),所以我试图用我的 Usercontroller 创建一个新用户: class UserController :new end
我正在尝试移植 bunny到 armv7h,它使用了一些我在转换为 asm 时遇到问题的 x86 asm 东西。 static __inline__ void atomic_inc(volatile
我一直在尝试向 https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/SystemService
以 one 作为参数调用 sleep 的预期持续时间是多少?它是一些不超过 1 秒的随机时间吗?它是某个至少为一秒的随机时间吗? 场景: 开发人员 A 编写代码,使用输出设备按顺序执行某些步骤。代码发
我正在尝试完成有关 Spring Boot 的教程,我目前在 JPA 部分,遇到了一个我无法解决的问题。我目前所处的位置是我已经构建了实体,我已经获得了 DB(H2 数据库)所需的所有依赖项,我已经构
我有如下代码,它检查我的命名函数是否已使用某些参数调用: const wrapper = mount(); let params = new URLSearchParams();
我正在使用Facebook Audience Network通过Android应用程序获利。 我11月份的估算收入大于$ 150,但即使到下个月的12月5日,在“支出”部分的“估算的支出”中仍然“未找
我试图在 Google 跟踪代码管理器中保存此自定义 Javascript 变量,但每次都返回此错误: sendinblue.identify('$_POST['_username']',{ '
该程序可在此处获取:http://ideone.com/P1c15J 这里简要介绍一下它的作用: 声明一个字符串ptr。将此指针地址转换为小端地址并将这些字节存储在 char[] adr 中。打印出来
我想使用 DynamicTimeWarping (DTW) 的输出进行分类。事实证明,动态时间扭曲算法的输出仍然需要进行后处理。作为时间对齐过程的一部分,数据 A 的一些单个数据点将被映射到数据 B
我正在尝试使用来自 GUI 的 Weka CSVLoader 将 CSV 转换为 ARFF。在选项中,我将字符串的包围字符设置为 " ,虽然我的文件中没有引号。 我收到以下错误: weka.core.
我是一名优秀的程序员,十分优秀!