这是一个新问题。试图更新数据库中的条目。注意,这个条目依赖于用户。当我没有与该项目没有任何问题的用户关联时,我执行了相同的逻辑。然而,现在它让我感到悲伤。这是屏幕截图:
以下是异常说明的详细信息:
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()