nerdexam
Microsoft

70-516 · Question #114

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. You write the following code segment. (Line…

The correct answer is B. context.MergeOption = MergeOption.PreserveChanges. PreserveChanges-Objects that do not exist in the object context are attached to the context. If the state of the entity is Unchanged, the current and original values in the entry are overwritten with data source values. The state of the entity remains Unchanged and no…

Querying 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. You write the following code segment. (Line numbers are included for reference only.) 01 AdventureWorksEntities context = new 02 ... 03 var q = from c in context.Customers 04 where c.City == "London" 05 orderby c.CompanyName 06 select c; You need to ensure that the application meets the following requirements:

  • Compares the current values of unmodified properties with values

returned from the data source.

  • Marks the property as modified when the properties are not the same.

Which code segment should you insert at line 02?

Options

  • Acontext.MergeOption = MergeOption.AppendOnly;
  • Bcontext.MergeOption = MergeOption.PreserveChanges;
  • Ccontext.MergeOption = MergeOption.OverwriteChanges;
  • Dcontext.MergeOption = MergeOption.NoTracking;

How the community answered

(45 responses)
  • A
    13% (6)
  • B
    76% (34)
  • C
    4% (2)
  • D
    7% (3)

Explanation

PreserveChanges-Objects that do not exist in the object context are attached to the context. If the state of the entity is Unchanged, the current and original values in the entry are overwritten with data source values. The state of the entity remains Unchanged and no properties are marked as modified. If the state of the entity is Modified, the current values of modified properties are not overwritten with data source values. The original values of unmodified properties are overwritten with the values from the data In the .NET Framework version 4, the Entity Framework compares the current values of unmodified properties with the values that were returned from the data source. If the values are not the same, the property is marked as modified. MergeOption Enumeration

Topics

#Entity Framework#MergeOption#PreserveChanges#change tracking

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice