What can we learn from Microsoft's dbml files (it tells us what is the top priority of Microsoft )~ In the binary dbcontext instance, how is a table object added?

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 main character of this series will always be linqtosql. dbml is generally called data object relationship ing or Orm. In short, it is a relationship between a database and an object. This relationship is called mapping. In linqtosql, we directly place a database object in the dbml file, and this relational ing is formed. That is to say, you can operate the database to directly operate the entity type in dbml in the future.

When we use an ORM tool, we always have a habit of abstracting what needs to be abstracted, because it is easier to manage and the structure is more object-oriented, should we abstract the linqtosql object class? In fact, Microsoft has already told us the answer when designing the linqtosql entity class, that is, "Yes, yes". We can see from the object type using the partial modifier that, microsoft hopes that we can reabstract it in a line and add the things required by the project to the entity class. In the project,CodeIt may be like this:

 1     ///   <Summary>  2      ///  User entity  4   ///   </Summary>  5      Public   Partial   Class  Userbases: entitybase  6   {  7          ///  <Summary>  8          ///  Unified primary key  9          ///   </Summary>  10          Protected   Override   Object  [] Primarykey  11   {  12              Get { Return  New   Object [] { This  . Userid };}  13   }  14   15          ///   <Summary>  16          ///  Field changes  17          ///   </Summary>  18         Public   Override   Void  Onpropertychange ()  19   {  20              If ( This . Isvalid) //  Whether the entity has been verified  21   22   {  23                  Base  . Onloaded (); 24                  This . Propertychanged + = New Propertychangedeventhandler ( Base  . Propertychangedevent );  25   }  26   }  27 }

 

 
In the userbases object, because it inherits the unified entity abstract class entitybase, the method parameters and return values can be written as follows when the data layer performs the unified entity Gurd operation:
 
 
1 Protected VirtualIqueryable <entitybase> getentities <tentity> (expression <func <tentity,Bool> Queryfunc)WhereTentity: entitybase2 {3}
 
 

 

 
 
 
Entity abstraction is not only linqtosql, but also applicable to the actual architecture.
 
 

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.