nerdexam
Microsoft

70-516 · Question #133

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

The correct answer is B. context.Refresh(RefreshMode.ClientWins, orders). SaveChanges() Persists all updates to the data source and resets change tracking in the object Refresh(RefreshMode, Object) Updates an object in the object context with data from the data AcceptAllChanges() Accepts all changes made to objects in the object context…

Manipulating and Validating Data

Question

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application. You use the ADO.NET Entity Framework to model entities. The application connects to a Microsoft SQL Server database named AdventureWorks. The application includes the following code segment. (Line numbers are included for reference only.) 01 using (AdventureWorksEntities context = new AdventureWorksEntities()) 02 { 03 ObjectQuery <SalesOrderHeader> orders = context.SalesOrderHeader. Where("it.CreditCardApprovalCode IS NULL").Top("100"); 04 foreach (SalesOrderHeader order in orders){ 05 order.Status = 4; 06 } 07 try { 08 context.SaveChanges(); 09 } 10 catch (OptimisticConcurrencyException){ 11 ... 12 } 13 } You need to resolve any concurrency conflict that can occur. You also need to ensure that local changes are persisted to the database. Which code segment should you insert at line 11?

Options

  • Acontext.Refresh(RefreshMode.ClientWins, orders);
  • Bcontext.Refresh(RefreshMode.ClientWins, orders);
  • Ccontext.Refresh(RefreshMode.StoreWins, orders);
  • Dcontext.Refresh(RefreshMode.StoreWins, orders);

How the community answered

(17 responses)
  • A
    12% (2)
  • B
    82% (14)
  • C
    6% (1)

Explanation

SaveChanges() Persists all updates to the data source and resets change tracking in the object Refresh(RefreshMode, Object) Updates an object in the object context with data from the data AcceptAllChanges() Accepts all changes made to objects in the object context. Refresh(RefreshMode refreshMode, Object entity) Method has the dual purpose of allowing an object to be refreshed with data from the data source and being the mechanism by which conflicts can be resolved. ObjectContext.Refresh Method

Topics

#Entity Framework#Refresh#RefreshMode#optimistic concurrency

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice