Back to directory
FirstArticleIt can be seen from the title that it mainly refers to the knowledge of assigning values to object attributes in dbml, as well as the sendpropertychanging and sendpropertychanged methods. From the fifth and sixth sections, we can see that the title is somewhat similar, yes, however, I will talk about their different focuses. The fifth part focuses on the attribute assignment process in the entity. At this time, the sendpropertychanging and sendpropertychanged methods will be used. The sixth part is about, the main focus is on the role of these two methods. First, let's talk about the event trigger mechanism.
1 Public String Predictionid 2 { 3 Get 4 { 5 Return This . _ Exceptionid; 6 } 7 Set 8 { 9 If (( This . _ Exceptionid! = Value )) 10 { 11 This . Onexceptionidchanging (value ); 12 This . Sendpropertychanging (); 13 This . _ Exceptionid = Value; 14 This . Sendpropertychanged ( " Predictionid " ); 15 This . Onexceptionidchanged (); 16 } 17 } 18 }
This is one of the following in the dbml entity class:CodeFragment, which is mainly used to assign values to the predictionid attribute. Get has nothing to say, and the value of this _ predictionid field has been returned. It mainly depends on the set part. Its workflow is as follows:
1. Determine whether the Variable _ predictionid is equal to the original value.
2. If not, call the onexceptionidchanging method to start modifying this field. It is a division method that can be implemented by developers according to their own logic.
3. sendpropertychanging
4. assign values to Fields
5. The method sendpropertychanged for calling the property has been modified, and the field modified by the method is "exceptionid"
6 onexceptionidchanged indicates that this field has been modified
Let's take a look at sendpropertychanging and sendpropertychanged.
1 Protected Virtual Void Sendpropertychanging () 2 { 3 If (( This . Propertychanging! = Null )) 4 { 5 This . Propertychanging ( This , Emptychangingeventargs ); 6 } 7 } 8 9 Protected Virtual Void Sendpropertychanged (string propertyname) 10 { 11 If (( This . Propertychanged! = Null )) 12 { 13 This . Propertychanged ( This , New Propertychangedeventargs (propertyname )); 14 } 15 }
These two methods are derived from the inotifypropertychanging and inotifypropertychanged interfaces. The main function is to notify the client that a property is to be modified and has been modified.
In the method body, in fact, it is used to trigger the following two events.
1Public EventPropertychangingeventhandler propertychanging;2 3Public EventPropertychangedeventhandler propertychanged;
That is to say, as long as the attribute is modified, the two facts will be triggered. What is the role of linqtosql in providing this function for us? Please refer to the following.
return to the directory