What can we learn from Microsoft's dbml files (it tells us what is the top priority of Microsoft )~ The four-segment method defines the type operation specifications from the other hand.

Source: Internet
Author: User

A dbcontext constructor, method Overloading

In the binary dbcontext instance, how is a table object added?

Does the three branch categories undermine a single responsibility?

The four-segment method defines the type operation specifications from the other hand.

5. assign values to attributes in the LINQ object class. Before and after the changes, sendpropertychanging and sendpropertychanged

Six linqtosql triggers sendpropertychanging and sendpropertychanged for us. What is its true intention?

7. The dbcontext object should be used as the base class of other object operation types and provide unified submission actions for it.

 

 

The partial method, which must be defined in the partial class.ArticleI have already mentioned the Division class. I believe you have an understanding of it. Today we mainly talk about the division method. The division method mainly aims to implement a function in the future, the method defined for this function is outstanding in the dbml file of LINQ to SQL.Code:

  Public partial class   Category :  inotifypropertychanging ,  inotifypropertychanged  { Private Static   propertychangingeventargs  emptychangingeventargs =  New   propertychangingeventargs  ( string . empty);  private int  _ id;  private string  _ name;  private int  _ parentid;  # region  extensibility method definition 
  partial void  onloaded ();  partial void  onvalidate (system. data. LINQ.  changeaction  action);  partial void  oncreated ();  partial void  onidchanging ( int  value);  partial void  onidchanged ();  partial void  onnamechanging ( string  value);  partial void  onnamechanged ();  partial void  onparentidchanging ( int  value);  partial void  onparentidchanged (); # endregion  
PublicCategory () {oncreated ();}
 
}
 
We can see that Microsoft has automatically added several branch methods for a LINQ object, but does not implement it.ProgramBut some methods will be referenced, such as the oncreated method.CategoryDivision class
 
The oncreated method can be implemented to execute our code when an entity instance is created.

On the other hand, the division method defines the type operation specification. This sentence is the topic of today. From the code above, we can see that the same is true. The division method marks the behaviors that can be included in the class, and call these actions.The developer determines it by himself. How is it flexible!

Let's take a look at how the partial method is used in my project. It implements the function of automatically executing code in the method body each time an object is instantiated, this section subscribes to a column modification event for an object.
 
Public classUserbases_ext:Userbases{}Public partial classUserbases:Entitybase{Protected override object[] Primarykey {Get{Return new object[] {This. Userid };}}/// <Summary> ///The object is automatically executed during initialization and is defined in the linqtosql source file.
/// </Summary>Partial voidOnloaded (){If(This. Isvalid)// Whether the entity has been verified{Base. Initialization ();// Initialize certain attributes of the base class
 
This. Propertychanged + =NewPropertychangedeventhandler(Base. Propertychangedevent );// When initializing an object, subscribe to the column modification event first.
 
}}
 
 

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.