Export (0) Print
Expand All

ObjectStateEntry.CurrentValues Property

Gets the current property values of the object or relationship associated with this ObjectStateEntry.

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

'Declaration
Public MustOverride ReadOnly Property CurrentValues As CurrentValueRecord
	Get

Property Value

Type: System.Data.Objects.CurrentValueRecord
A CurrentValueRecord that contains the current values of the object or relationship associated with this ObjectStateEntry.

The returned CurrentValueRecord is a conceptual-schema view of the values in the object or relationship. It is not a copy; it delegates to the data that are actually in the entity object.

Complex type properties in an object are returned as nested CurrentValueRecord objects.

All properties can be edited when the entity is in the added state, but key values are read-only when the entity is in other states other than added or detached.

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 the SalesOrderHeader.PurchaseOrderNumber property, changes the property's value, and enumerates through the collection of modified properties.


Dim orderId As Integer = 43680

Using context As New AdventureWorksEntities()
    Dim order = (From o In context.SalesOrderHeaders
            Where o.SalesOrderID = orderId
            Select o).First()

    ' Get ObjectStateEntry from EntityKey. 
    Dim stateEntry As ObjectStateEntry = _
        context.ObjectStateManager.GetObjectStateEntry(DirectCast(order, IEntityWithKey).EntityKey)

    'Get the current value of SalesOrderHeader.PurchaseOrderNumber. 
    Dim rec1 As CurrentValueRecord = stateEntry.CurrentValues
    Dim oldPurchaseOrderNumber As String = _
        DirectCast(rec1.GetValue(rec1.GetOrdinal("PurchaseOrderNumber")), String)

    'Change the value. 
    order.PurchaseOrderNumber = "12345"
    Dim newPurchaseOrderNumber As String = _
        DirectCast(rec1.GetValue(rec1.GetOrdinal("PurchaseOrderNumber")), String)

    ' Get the modified properties. 
    Dim modifiedFields As IEnumerable(Of String) = stateEntry.GetModifiedProperties()
    For Each s As String In modifiedFields
        Console.WriteLine("Modified field name: {0}", s)
        Console.WriteLine("Old Value: {1}", oldPurchaseOrderNumber)
        Console.WriteLine("New Value: {2}", newPurchaseOrderNumber)
    Next

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


.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.

Community Additions

ADD
Show:
© 2014 Microsoft