I have an Entity Data Model built using Devart's Entity Developer. It is a database first model and I set the template properties to implement INotifyPropertyChanged (and Changing) and to create separate partial classes for each entity in the model.
With the model built I am now looking at some auto generated code in the model for a property of an entity that looks like this:
Public Overridable Property Rc() As Global.System.Nullable(Of Integer)
Get
Return _Rc
End Get
Set
If (Object.Equals(_Rc, value) = false) Then
OnPropertyChanging("Rc")
_Rc = value
OnPropertyChanged("Rc")
End If
End Set
End Property
Private _Rc As Global.System.Nullable(Of Integer)
with further sections relating to INotifyPropertyChanged and Changing:
#Region "INotifyPropertyChanging Members"
Public Event PropertyChanging(sender As Object, e As PropertyChangingEventArgs) Implements INotifyPropertyChanging.PropertyChanging
Protected Sub OnPropertyChanging(propertyName As String)
RaiseEvent PropertyChanging(Me, New PropertyChangingEventArgs(propertyName))
End Sub
#End Region
#Region "INotifyPropertyChanged Members"
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
Protected Sub OnPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
The model created a separate partial class for this entity and I assume that it should be in that partial class that I should put any code that I want that will react to the OnPropertyChanged. So for example with the property illustrated in the code snippet above (which would typically represent a year in the form of 2014) I would like to set the value of another of the entities properties to be 2014 + 5 ie 2019.
Could anyone explain to me how I should do this. I'd prefer vb if possible but can work with c#.
Thanks
For the benefit of others who may come to this at some point in the future.
I had an entity model built in its own project (so it was in effect a separate data layer) for a couple of solutions I am building. Each entity has its own separate partial class into which I add custom code. I knew that I would need to handle the PropertyChanged event in that partial class but I was constantly struggling to 'see' which property had fire the event.
It turns out that I had made a simple but fundamental mistake. Originally I had created the following method:
Private Sub OnPropertyChangedLogicImplementation(sender As Object, e As EventArgs) Handles Me.PropertyChanged
Select Case e.PropertyName
Case
End Select
End Sub
The reason it didn't work was that I had used EventArgs as opposed to PropertyChangedEventArgs which simply couldn't pick up the propertyname that I was expecting to be able to pick up.
Private Sub OnPropertyChangedLogicImplementation(sender As Object, e As PropertyChangedEventArgs) Handles Me.PropertyChanged
Select Case e.PropertyName
Case
End Select
End Sub
Oddly there is very little in the way of direct examples of how to do this that I could find and hence my original question. Hopefully this will save someone else wasting time looking for the painfully obvious (once of course you realise that it's painfully obvious!).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.