nerdexam
Microsoft

70-516 · Question #93

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application. You use the ADO.NET Entity Framework Designer to model entities. You need to associate a previously…

The correct answer is C. model.AttachTo("People", person1). Cosiderations from Attaching and Detaching objects 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 Attach Use the Attach method of…

Implementing Data Access

Question

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application. You use the ADO.NET Entity Framework Designer to model entities. You need to associate a previously deserialized entity named person1 to an object context named model and persist changes to the database. Which code segment should you use?

Options

  • Aperson1.AcceptChanges();
  • Bmodel.People.ApplyChanges(person1) ;
  • Cmodel.AttachTo("People", person1);
  • Dmodel.People.Attach(person1);

How the community answered

(19 responses)
  • A
    5% (1)
  • B
    21% (4)
  • C
    68% (13)
  • D
    5% (1)

Explanation

Cosiderations from Attaching and Detaching objects 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 Attach Use the Attach method of ObjectContext where the method accepts a single typed entity AttachTo The AttachTo method of ObjectContext accepts two parameters. The first parameter is a string containing the name of the entity set. The second parameter' type is object and references the entity you want to add. Attach The Attach method of ObjectSet, which is the entity set' type, accepts a single typed parameter containing the entity to be added to the ObjectSet. CHAPTER 6 ADO.NET Entity Framework Lesson 2: Querying and Updating with the Entity Framework Attaching Entities to an ObjectContext(page 437) Attaching and Detaching objects

Topics

#Entity Framework#AttachTo#detached entity#ObjectContext

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice