DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353

    Entity Value Comparison

    I need to reference the original values of an entity before doing a SaveChanges(). Is the value in the store available and what is the syntax to access it?

    Example: I have an Employee entity and change the Hours of the employee. How can I determine, before I implement the SaveChanges() that Hours has been modified?

    ...joe

  2. #2
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    Figured out a solution:

    Code:
    Sub CheckModifiedValues(ByVal Context As ObjectContext)
            Try
                'Get all objects modified
                Dim Changes As IEnumerable(Of ObjectStateEntry) = Context.ObjectStateManager.GetObjectStateEntries(EntityState.Modified)
                If Changes.Count > 0 Then
                    'Loop through changed objects
                    For Each Obj In Changes
                        'get the properties modified for the object
                        Dim ModifiedProperties As IEnumerable(Of String) = Obj.GetModifiedProperties
                        If ModifiedProperties.Count > 0 Then
                            For Each prop As String In ModifiedProperties
                                'these will error if you pass through a property that was not modified - thus the GetModifiedProperties
                                Dim strOrg As String = Obj.OriginalValues(prop).ToString
                                Dim strMod As String = Obj.CurrentValues(prop).ToString
                                MessageBox.Show("Current " & prop & ": " & strMod & " Original " & prop & ": " & strOrg)
                            Next
                        End If
                    Next
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub

    ...joe

Similar Threads

  1. a simple question about design patterns
    By mkamoski in forum .NET
    Replies: 1
    Last Post: 08-13-2009, 07:41 PM
  2. Comparison methods
    By ericelysia1 in forum Java
    Replies: 34
    Last Post: 05-15-2005, 06:39 PM
  3. Replies: 0
    Last Post: 09-28-2002, 06:23 PM
  4. entity references in XSD definitions?
    By unknown in forum XML
    Replies: 0
    Last Post: 04-02-2002, 11:15 AM
  5. Replies: 1
    Last Post: 05-10-2000, 05:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links