nerdexam
Microsoft

70-515 · Question #159

You are implementing an ASP.NET application that uses LINQ to Entities to access and update the database. The application includes the following method to update a detached entity of type Person…

The correct answer is A. _entities.People.Attach(personToEdit). See the full explanation below for the reasoning.

Question

You are implementing an ASP.NET application that uses LINQ to Entities to access and update the database. The application includes the following method to update a detached entity of type Person. private NorthwindContext _entities; public void UpdatePerson(Person personToEdit) { } You need to implement the UpdatePerson method to update the database row that corresponds to the personToEdit object. Which code segment should you use?

Options

  • A_entities.People.Attach(personToEdit);
  • B_entities.ObjectStateManager.ChangeObjectState(personToEdit,
  • C_entities.People.ApplyCurrentValues(personToEdit);
  • D_entities.People.Attach(new Person() { Id = personToEdit.Id });

How the community answered

(19 responses)
  • A
    79% (15)
  • B
    5% (1)
  • C
    5% (1)
  • D
    11% (2)

Community Discussion

No community discussion yet for this question.

Full 70-515 Practice