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.
}}