Which code segment should you insert at line 05?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 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.)
01public partial class SalesOrderDetail : EntityObject
02{
03partial void OnOrderQtyChanging(short value)
04{
05
06{
07…
08}
09}
10}
You need to find out whether the object has a valid ObjectStateEntry instance. Which code segment
should you insert at line 05?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 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.)
01public partial class SalesOrderDetail : EntityObject
02{
03partial void OnOrderQtyChanging(short value)
04{
05
06{
07…
08}
09}
10}
You need to find out whether the object has a valid ObjectStateEntry instance. Which code segment
should you insert at line 05?

A.
if (this.EntityState != EntityState.Detached)

B.
if (this.EntityState != EntityState.Unchanged)

C.
if (this.EntityState != EntityState.Modified)

D.
if (this.EntityState != EntityState.Added)

Explanation:
Detached The object exists but is not being tracked. An entity is in this state immediately after it has
been created and before it is added to the object context. An entity is also in this state after it has
been removed from the context by calling the Detach method or if it is loaded by using a NoTracking
MergeOption. There is no ObjectStateEntry instance associated with objects in the Detached state.
Unchanged The object has not been modified since it was attached to the context or since the last
time that the SaveChanges method was called.
Added The object is new, has been added to the object context, and the SaveChanges method has
not been called.
After the changes are saved, the object state changes to Unchanged. Objects in the Added state do
not have original values in the ObjectStateEntry.
Deleted The object has been deleted from the object context. After the changes are saved, the
object state changes to Detached.
Modified One of the scalar properties on the object was modified and the SaveChanges method has
not been called.
In POCO entities without change-tracking proxies, the state of the modified properties changes to
Modified when the DetectChanges method is called. After the changes are saved, the object state
changes to Unchanged.
EntityState Enumeration
(http://msdn.microsoft.com/en-us/library/system.data.entitystate.aspx)
CHAPTER 6 ADO.NET Entity Framework

Lesson 1: What Is the ADO.NET Entity Framework?
Storing Information about Objects and Their State (page 381)



Leave a Reply 0

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