What can we learn from Microsoft's dbml files (it tells us what is the top priority of Microsoft )~ 5. assign values to attributes in the LINQ object class. Before and after changes, sendpropertychanging and sendpropertychange

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.