Same primary key issue Ask Question
By   Tashif Ghaffar     04-May-2024    2

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
03
07

New Messages

George Floyd
  • Edit Post Edit This Post within a Hour
  • Hide Chat Hide This Post
  • Delete Chat If inappropriate Post By Mistake
  • Report Inappropriate Chat
  • 4.5kb
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks