nerdexam
Microsoft

70-516 · Question #142

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application. The application connects to a Microsoft SQL Server database. The application uses the ADO.NET Entity…

The correct answer is C. AddObject. ObjectContext.AddObject() Call AddObject on the ObjectContext to add the object to the object Do this when the object is a new object that does not yet exist in the data source. ObjectContext.Attach() Call Attach on the ObjectContext to attach the object to the object context…

Manipulating and Validating Data

Question

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application. The application connects to a Microsoft SQL Server database. The application uses the ADO.NET Entity Framework to manage order data. The application makes a Web service call to obtain orders from an order-tracking system. You need to ensure that the orders are added to the local data store. Which method should you call on the ObjectContext?

Options

  • AAttach
  • BAttachTo
  • CAddObject
  • DApplyCurrentValues

How the community answered

(36 responses)
  • A
    11% (4)
  • B
    3% (1)
  • C
    78% (28)
  • D
    8% (3)

Explanation

ObjectContext.AddObject() Call AddObject on the ObjectContext to add the object to the object Do this when the object is a new object that does not yet exist in the data source. ObjectContext.Attach() Call Attach on the ObjectContext to attach the object to the object context. Do this when the object already exists in the data source but is currently not attached to the If the object being attached has related objects, those objects will also be attached to the object Objects are added to the object context in an unchanged state. The object that is passed to the Attach method must have a valid EntityKey value. If the object does not have a valid EntityKey value, use the AttachTo method to specify the name of the entity ObjectContext.AttachTo() Call AttachTo on the ObjectContext to attach the object to a specific entity set in the object context or if the object has a null (Nothing in Visual Basic) EntityKey value. The object being attached is not required to have an EntityKey associated with it. If the object does not have an entity key, then entitySetName cannot be an empty string. ApplyCurrentValues<TEntity>() method is used to apply changes that were made to objects outside the ObjectContext, such as detached objects that are received by a Web service. The method copies the scalar values from the supplied object into the object in the ObjectContext that has the same key. You can use the EntityKey of the detached object to retrieve an instance of this object from the

Topics

#ObjectContext#AddObject#entity tracking#Entity Framework

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice