How can I retrieve the object properties values from the database?

How can i retrieve the object properties values from the database, in my action method?

  • I have the following Post Edit action method, which include a [Bind] list to restrict the properties that the model binder will bind:- [HttpPost] public ActionResult Edit(Bind(Include="Note,DoctorID,VisitID,StatusID")] Visit visit) { if ((visit.EditableByAssingedDoctor(User.Identity.Name)) || (visit.EditableByCreatedBy(User.Identity.Name))) { try {if (ModelState.IsValid) { entities.Entry(visit).State = EntityState.Modified; repository.Save(); return RedirectToAction("Index"); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Visit)entry.Entity; //code goes here But since the Visit Object contains other properties that are not included in the bind list,, so how i can retrieve the current values for the Visit object properties from the database. Hint:- I am using entity framework with database first approach. BR UPDATED:- HERE IS THE GET EDIT action method:- public ActionResult Edit(int id) { Visit visit = repository.GetVisit(id); if ((visit.EditableByAssingedDoctor(User.Identity.Name)) || (visit.EditableByCreatedBy(User.Identity.Name))) { ViewBag.DoctorID = new SelectList(Membership.GetAllUsers(), "Username", "Username", visit.DoctorID); ViewBag.StatusID = new SelectList(repository.FindAllVisitStatus(), "StatusID", "Description", visit.StatusID); return View(visit); } else { return View("NotFound");} }

  • Answer:

    It looks like only the Note is editable, except sometimes the Status is editable as well? Based on http://stackoverflow.com/q/10326538/1284283. I'm going out on a limb here since I don't know what your HTTPGet method looks like, and I'm rusty in EF. I'm excluding the necessary checks, try/catch, etc... var dbVisit = repository.GetVisit(visit.VisitId); dbVisit.Note = visit.Note; // if this is permissible if (dbVisit.IsEditable(...)){ ... whatever is permissible here ... } repository.UpdateVisit(dbVisit); // possibly inside the if clause above ... etc ...

john G at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.