Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that uses the EntityFramework.
The application has an entity named Person. 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?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that uses the EntityFramework.
The application has an entity named Person. 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?

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.ExecuteStoreCommand(“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 0

Your email address will not be published. Required fields are marked *