This documentation is archived and is not being maintained.

ObjectStateEntry.GetModifiedProperties Method

Returns the names of an object's properties that have changed since the last time SaveChanges was called.

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

public IEnumerable<string> GetModifiedProperties()

Return Value

Type: System.Collections.Generic.IEnumerable<String>
An IEnumerable<T> collection of names as String.

Returns the property names that are marked Modified.

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.

int orderId = 43680;

using (AdventureWorksEntities advWorksContext =
    new AdventureWorksEntities())
        SalesOrderHeader order =
            ("it.SalesOrderID = @id", new ObjectParameter(
             "id", orderId)).First();

        // Get ObjectStateEntry from EntityKey.
        ObjectStateEntry stateEntry =

        //Get the current value of SalesOrderHeader.PurchaseOrderNumber.
        CurrentValueRecord rec1 = stateEntry.CurrentValues;
        string oldPurchaseOrderNumber = 

        //Change the value.
        order.PurchaseOrderNumber = "12345";
        string newPurchaseOrderNumber = 

        // Get the modifed 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);
    catch (EntitySqlException ex)
    catch (EntityCommandExecutionException ex)

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1