Same primary key issue Ask Question
By   Tashif Ghaffar     12-Jul-2024    1

QUESTION : 

System.Data.Entity.Validation.DbEntityValidationException

HResult=0x80131920

Message=Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

Source=EntityFramework

StackTrace:

at System.Data.Entity.Internal.InternalContext.SaveChanges()

at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()

at System.Data.Entity.DbContext.SaveChanges()

at InnerException.WebUI.Controllers.ManageDailyRoutinesController.Create(DailyRoutine dailyRoutine) in F:\future_developement\InnerException\InnerException.WebUI\Controllers\ManageDailyRoutinesController.cs:line 48

at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)

at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)

at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)

at System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)

at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)

at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()

at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)

at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()

at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()

now this error happen on save changes

ANSWER:
This error ocurred when one varible overlap with (db.Entry(variableName).State = EntityState.Modified;) you can solve it easily make one more if and else (nested if) put your condition and write this code :

db.Entry(variableName).CurrentValues.SetValues(dbName);
db.Entry(variableName).State = EntityState.Modified;
db.Entry(variableName).Property(x => x.(your property which you want to called it there from db).IsModified = false;

Solutions


10394
Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM