I am working with ASP.NET MVC3 using EF and Code First.
I am writing a simple sampler for practice. In my controller I have a pretty standard code bit:
[HttpPost] public ActionResult Edit(Issue issue) { if (ModelState.IsValid) { dbContext.Entry(issue).State = EntityState.Modified ..... } }
Part of Question 1 I am trying to understand how dbcontext works - Before I set the state to dbContext.Entry (problem), I assume that my problem object is detached. As soon as I set the state to be changed, the object is attached - but to what? dbContext or database? I donโt seem to understand what this means (attachment) really means?
Part of question 2 For argumentation, let's say I decided to set the Accepted field in my problem. Accepted is logical. I start by saying that this is a lie, I set it to true and in form. At the moment when my object is attached, what is the point of the OriginalValues โโcollection? for example, if I set a breakpoint right after setting EntityState.Modified, but before calling SaveChanges () I can request
db.Entry(issue).OriginalValues["Accepted"]
and this will give me the same meaning as just querying the problem object that was passed to Edit .... i.e. it gives the same result as
issue.Accepted
I am clearly missing something because the documentation says "The initial values โโare usually the values โโof the properties of the object, as they were when the last query from the database." But this is not so, because the database still reports that it is accepted as false (yes, I noticed the word โusuallyโ in the documents, but my code is pretty much standard, generated by the MS code, so ...). So what am I missing? what is really going on here?
source share