Source=EntityFramework StackTrace: at System.Data.Entity.Core.Objects.ObjectContext.VerifyRootForAdd(Boolean doAttach, String entitySetName, IEntityWrapper wrappedEntity, EntityEntry existingEntry, EntitySet& entitySet, Boolean& isNoOperation) at System.Data.Entity.Core.Objects.ObjectContext.AttachTo(String entitySetName, Object entity) at System.Data.Entity.Internal.Linq.InternalSet`1.<>c__DisplayClassa.<Attach>b__9() at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) at System.Data.Entity.Internal.Linq.InternalSet`1.Attach(Object entity) at System.Data.Entity.DbSet`1.Attach(TEntity entity) at SysManager.Repository.RepositoryBaseWithList`2.Update(T entity) in D:\_Siriusware\Main\SysManager\SysManager.Repository\RepositoryBaseWithList.cs:line 158 at SysManager.Adapter.PreferencesAdapter.Update(Prefs prefs) in D:\_Siriusware\Main\SysManager\SysManager.Adapter\PreferencesAdapter.cs:line 155 at SysManager.Web.Areas.AdmissionControl.Controllers.AccessApiController.UpdatePrefs(EditPrefsViewModel prefsViewModel) in D:\_Siriusware\Main\SysManager\SysManager.Web\Areas\AdmissionControl\Controllers\AccessApiController.cs:line 253 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) InnerException:-----------------------------------
public virtual void Update(T entity) { try { EntityState entityState = _siriusContext.GetEntityState(entity); if (entityState == EntityState.Detached) { _dbSet.Attach(entity); _siriusContext.SetModified(entity); } SaveChanges(); } //catch here }The error happens on the Attach line. I was thinking it may be due to not re-loading the model data after saving, but I added that code into script controller and still get the same error, so I'm not sure how to fix it now.