c# - Optimistic Concurrency issue when Updating in MVC -


In MVC3, in the unit framework project, I am using a view modal (for mapping objects and automaps) in the scene view.

when the phone db.SaveChanges (); (see edit) returns an error,

An error occurs when saving such entities that do not expose the foreign entities EntityEntries property properties for their relationships Will come back because one entity can not be identified as the source of exception. While handling exceptions, savings can be made easier by highlighting foreign key properties in your unit types. View inner expansions for details

Inner exception is

Store updates, insert, or delete stores affected by the unexpected number of statements (0). Institutions may have been modified or deleted since the institutions have been loaded. Refresh ObjectTinet Manager entries.

I processed this error message on the web and now I think this is the optimist conductor issue, which is defined in more than one relationship < Em> post model,

post. Posted - & gt; User

Post. Author - & gt; Author can be

(This may be because the post model I am trying to update is different and there is no current value when calling SaveChanges

Model Public Sector Post {{Key} Public IIT {Receive; Set; } ... Posted by Public Virtual User {get; Set; } Receive public virtual author authors; Set; }} Public Class User {[Key] Public Virtual GUID UserId {get; Set; } ... public virtual icon & lt; Post & gt; Post {get; Set; }} Public class author {public id id}; Set; } ... public virtual icon & lt; Post & gt; Post {get; Set; }}

Controller

  [HTTPP] Edit Public Functionality (PostEdit Vivamodel PostEdit Vivamodel, FormCollection Form) {if ( ModelState.IsValid) {Var Post = Mapper Map & lt; PostEditViewModel, Post & gt; (PostEditViewModel); Db.Entry (post) .set = EntityState.Modified; String author id = form ["writer"]; Post. Author = GetAuthorById (Convert.ToInt32 (authorId)); Post.PostedBy = GetUserByName (User.Identity.Name); Db.SaveChanges (); Return Redirect Action ("Index"); } See Return (PostEditV.Movell); }   

Please help me to solve this problem ...

>

Comments