Export (0) Print
Expand All

ObjectStateEntry Class

Maintains state and key information for objects and relationships and change tracking for object properties.

System.Object
  System.Data.Objects.ObjectStateEntry

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public abstract class ObjectStateEntry : IEntityChangeTracker

The ObjectStateEntry type exposes the following members.

  NameDescription
Public propertyCurrentValuesGets the current property values of the object or relationship associated with this ObjectStateEntry.
Public propertyEntityGets the object associated with this ObjectStateEntry.
Public propertyEntityKeyGets the EntityKey associated with the ObjectStateEntry.
Public propertyEntitySetGets the EntitySetBase for the object or relationship associated with this ObjectStateEntry.
Public propertyIsRelationshipGets a Boolean value that indicates whether this ObjectStateEntry represents a relationship.
Public propertyObjectStateManagerGets the ObjectStateManager for this ObjectStateEntry.
Public propertyOriginalValuesGets the read-only version of original values of the object or relationship associated with this ObjectStateEntry. To get updatable original values, use GetUpdatableOriginalValues.
Public propertyRelationshipManagerReturns a RelationshipManager instance for the object represented by entry.
Public propertyStateGets the state of this ObjectStateEntry.
Top

  NameDescription
Public methodAcceptChangesAccepts the current values as original values.
Public methodApplyCurrentValuesSets the current values of the entry to match the property values of a supplied object.
Public methodApplyOriginalValuesSets the original values of the entry to match the property values of a supplied object.
Public methodChangeStateChanges state of the entry to the specified EntityState value.
Public methodDeleteMarks an entity as deleted.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetModifiedPropertiesReturns the names of an object's properties that have changed since the last time SaveChanges was called.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetUpdatableOriginalValuesGets the updatable version of original values of the object associated with this ObjectStateEntry.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSetModifiedSets the state of the object or relationship to Modified.
Public methodSetModifiedPropertyMarks the specified property as modified.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIEntityChangeTracker.EntityComplexMemberChangedNotifies the state manager that a complex property has changed.
Explicit interface implemetationPrivate methodIEntityChangeTracker.EntityComplexMemberChangingNotifies the state manager that a complex property has a pending change.
Explicit interface implemetationPrivate methodIEntityChangeTracker.EntityMemberChangedNotifies the state manager that a property has changed.
Explicit interface implemetationPrivate methodIEntityChangeTracker.EntityMemberChangingNotifies the state manager that a property has a pending change.
Explicit interface implemetationPrivate propertyIEntityChangeTracker.EntityStateGets the EntityState for the ObjectStateEntry.
Top

Maintains the EntityState, the EntityKey values, and the original values of an object or relationship. Also manages the list of modified properties.

There is an instance of an ObjectStateEntry associated with each entity type relationship instance. An object is associated with an ObjectStateEntry only if it is in the ObjectStateManager.

When an object that has a relationship is detached, the information maintained by the ObjectStateEntry is reduced to only what is required to maintain the relationship.

An ObjectStateEntry cannot have the same key as another ObjectStateEntry in the same ObjectStateManager.

The key values of a persisted entity cannot be modified. Entities in the unchanged, modified, and deleted states are persisted entities.

The example in this topic is based on the Adventure Works Sales Model. The example gets the ObjectStateEntry for the given EntityKey from the ObjectStateManager. Then it gets the current value of SalesOrderHeader.PurchaseOrderNumber property, changes the property's value, and enumerates through the collection of modified properties.


int orderId = 43680;

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    var order = (from o in context.SalesOrderHeaders
                 where o.SalesOrderID == orderId
                 select o).First();

    // Get ObjectStateEntry from EntityKey.
    ObjectStateEntry stateEntry =
        context.ObjectStateManager
        .GetObjectStateEntry(((IEntityWithKey)order).EntityKey);

    //Get the current value of SalesOrderHeader.PurchaseOrderNumber.
    CurrentValueRecord rec1 = stateEntry.CurrentValues;
    string oldPurchaseOrderNumber =
        (string)rec1.GetValue(rec1.GetOrdinal("PurchaseOrderNumber"));

    //Change the value.
    order.PurchaseOrderNumber = "12345";
    string newPurchaseOrderNumber =
        (string)rec1.GetValue(rec1.GetOrdinal("PurchaseOrderNumber"));

    // Get the modified properties.
    IEnumerable<string> modifiedFields = stateEntry.GetModifiedProperties();
    foreach (string s in modifiedFields)
        Console.WriteLine("Modified field name: {0}\n Old Value: {1}\n New Value: {2}",
            s, oldPurchaseOrderNumber, newPurchaseOrderNumber);

    // Get the Entity that is associated with this ObjectStateEntry.
    SalesOrderHeader associatedEnity = (SalesOrderHeader)stateEntry.Entity;
    Console.WriteLine("Associated Enity's ID: {0}", associatedEnity.SalesOrderID);
}


.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft