locked
PropertyChanged RRS feed

Answers

All replies

  • Hi Alejandro Cruzado,

    According to your according, I think you could use INotifyPropertyChanged to implement your requirement, you could create a partial class, which inherit the interface named INotifyPropertyChanged, like this:

      Public Partial Class OrderInfo
     Public Property Id() As Integer
      Get
       Return m_Id
      End Get
      Set
       m_Id = Value
      End Set
     End Property
     Private m_Id As Integer
     <StringLength(50)> _
     Public Property ProductCategory() As String
      Get
       Return m_ProductCategory
      End Get
      Set
       m_ProductCategory = Value
      End Set
     End Property
     Private m_ProductCategory As String
     <Column(TypeName := "numeric")> _
     Public Property Amount() As System.Nullable(Of Decimal)
      Get
       Return m_Amount
      End Get
      Set
       m_Amount = Value
      End Set
     End Property
     Private m_Amount As System.Nullable(Of Decimal)
     Public Property Status() As System.Nullable(Of Integer)
      Get
       Return m_Status
      End Get
      Set
       m_Status = Value
      End Set
     End Property
     Private m_Status As System.Nullable(Of Integer)
    End Class

    partial class which inherit interface.

    Public Partial Class OrderInfo
    	Implements INotifyPropertyChanged
    	Public Property InfoId() As Integer
    		Get
    			Return Me.Id
    		End Get
    		Set
    				' Do INotifyPropertyChangedLogic
    			Me.Id = value
    		End Set
    	End Property
    
    	' Implement INotifyPropertyChanged
    	Public Event PropertyChanged As PropertyChangedEventHandler
    
    End Class
    

    For more information, please refer to:

    http://stackoverflow.com/questions/18835827/how-to-implement-inotifypropertychanged-on-entity-framework-entity

    http://stackoverflow.com/questions/18835827/how-to-implement-inotifypropertychanged-on-entity-framework-entity

    https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

    Best regards,

    Cole Wu

    Thursday, April 14, 2016 1:38 AM
  • OK thank you very much.


    The question is about how to detect the value of the property changes as a result of the materialization of the object.


    Thursday, April 14, 2016 2:56 AM
  • In the link mentioned there is a solution that uses EntityState within the class of the entity.

    I would like to know how to adapt this code since I'm using dbContext.

    Thursday, April 14, 2016 3:02 AM
  • OK thank you very much.


    The question is about how to detect the value of the property changes as a result of the materialization of the object.



    You can't there is no way to detect it as to how the property was changed by a object metallization or by other means.   
    Thursday, April 14, 2016 3:23 AM
  • When I work with entities detached from dbcontext I usually wrap them in a self tracking object.

    In wpf this would be a viewmodel.

    And here's an article and working sample which tracks when users change properties.

    http://social.technet.microsoft.com/wiki/contents/articles/30939.wpf-change-tracking.aspx

    That just uses plain objects rather than EF objects but an entity object could easily be substituted for Media.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Thursday, April 14, 2016 6:06 PM