c# - 实体与身份用户关联时,实体框架核心 3.2 更新失败
问题描述
这是一个新问题。试图更新数据库中的条目。注意,这个条目依赖于用户。当我没有与该项目没有任何问题的用户关联时,我执行了相同的逻辑。然而,现在它让我感到悲伤。这是屏幕截图:
以下是异常说明的详细信息:
System.InvalidOperationException
HResult=0x80131509
Message=The property 'Id' on entity type 'Medication' has a temporary value while attempting to change the entity's state to 'Modified'. Either set a permanent value explicitly or ensure that the database is configured to generate values for this property.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey)
at Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry.set_State(EntityState value)
at MedicalManager.Models.Repositories.MedicationRepository.UpdateMedication(Medication medication, String UserId) in C:\bite-us\stackoverflow\mmm_development\MedicalManager\Models\Repositories\MedicationRepository.cs:line 71
at MedicalManager.Controllers.HomeController.Edit(Medication medication) in C:\bite-us\stackoverflow\mmm_development\MedicalManager\Controllers\HomeController.cs:line 123
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
解决方案
推荐阅读
- wordpress - 如何为每个不同类别的帖子排序?
- image - 如何在 JavaFX 中制作矩形图像以用作 Treeview 图标
- r - 如何将数字列表中的值添加到绘图标题?
- c# - 如何使用 Stripe.NET 预览按比例分配?
- python - python web 抓取 - len(containers) 总是返回 0
- azure-durable-functions - 当设置了 backoffCoefficient 时,如何计算持久函数的下一次重试时间?
- ios - 如何在 Swift 的 HeightForRowAt 函数中设置 UITableViewCell 的大小后调整其大小?
- c# - 为什么泛型约束不能帮助编译器在具有可选参数的多态方法中做出决定?
- javascript - 屏幕上有太多物体时的碰撞问题
- python - 屈服然后返回还是仅仅返回?