PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft .NET Framework 4 to develop an application that uses the Entity Framework. The
application has an entity model with a Person entity. A Person instance named person1 and an
ObjectContext instance named model exist. You need to delete the person1 instance. Which code
segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
model.DeleteObject(person1);
model.SaveChanges();

B.
model.Detach(person1);
model.SaveChanges();

C.
model.ExecuteStoreCommand(“Delete”, new []
{ new ObjectParameter(“Person”, person1) });
model.SaveChanges();

D.
model.ExecuteFunction(“Detach”, new []
{ new ObjectParameter(“Person”, person1) });
model.SaveChanges();

Explanation:
ObjectContext.DeleteObject Marks an object for deletion from the ObjectStateManager. The object
is deleted in the data source when the SaveChanges method is called.

ObjectContext.ExecuteStoreCommand Method executes an arbitrary command directly against the
data source using the existing connection.


Leave a Reply