|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| a simple question about design patterns | mkamoski | .NET | 1 | 08-13-2009 08:41 PM |
| Comparison methods | ericelysia1 | Java | 34 | 05-15-2005 07:39 PM |
| How to call the ejbCreate() method of an entity bean from WITHIN the entity bean | Jared Dinerstein | Java | 0 | 09-28-2002 07:23 PM |
| entity references in XSD definitions? | unknown | XML | 0 | 04-02-2002 12:15 PM |
| Wanted: Entity EJBs With Configurable Attributes | Jim Bowman | Java | 1 | 05-10-2000 06:20 PM |