Step by step teach you how to use the agileeas. net base class library for application development-basics-ORM accessors and Their Configurations

Source: Internet
Author: User
Series Review

The first three articles in this seriesArticleIntroduced and demonstrated agileeas. the development process of the ORM Component on the net platform and its common usage methods. Through the previous three articles, everyone can normally use the ORM for normal development, this article will mention An ORM structural problem, the orm object accessors.

Description

When talking about the ORM accessors, we have to mention a problem facing the object design, that is, the object. operation () or operator. operation (object), for such a question that is controversial and does not have a clear problem of optimal results, I do not dare to introduce it in detail in this article, I will publish a discussion at the right time: Objects in object-oriented design. operation () or operator. operation (object ).

Access Mode change

Agileeas. the ORM in the net platform was first based on objects. in the initial version, the ORM object (ientity) and Table object (itable) included the basic operations of the ORM: read, update, delete, and plug-in operations:

We can see from the definition of ientity that the object record interface defines the operations for synchronizing queries, refresh, inert, update, and delete to the database, and also defines cache refresh operations such as cacherefresh, the same itable object also defines its operations:

The itable interface defines query, update, delete, and other operations synchronized with the database, as well as cache query operations such as cachequery.

In the initial ORM implementation, these methods are directly implemented in two base classes: itable and ientity, table and entity. In essence, the itable and ientity interfaces do not exist in the highest ORM system, at that time, there was no need for an interface-based driver.

So far, the ORM object (ientity and itable) also includes the definition of this set of methods, which are very common in the long term of application development such as prodct. insert.

In agileeas. in the history of the change of the. NET platform Orm, two things have changed the ORM object and its access system. The first thing is, the same application needs to run on different databases to drive interface-based data layer development, that is, the itable and ientity interfaces are proposed, the second thing is that the SAAs/distributed application environment gave birth to the ORM accesser, which further separated the definition and operation of ORM components.

Let's take a look at the definition of the orm accessor iormaccessor:

Cache accessors icacheaccessor:

The Platform directory is in eas. Data. dllProgramA database-based ormaccessor is built in CIMC. It must connect iconnection and iaccessor based on an existing database, it also has a built-in memory-based ORM cache accessor (cacheaccessor ).

At the same time, a distributed ORM accesser Based on remoting and WebService is implemented on the agileeas. NET platform.

With the ORM accessors, we can use the operator-manipulate (object) mode during application development to perform ORM operations, such as ormaccessor. insert (product ).

Integration of two modes

Agileeas. the ORM in the. NET platform provides the operator through the orm accessors. for this processing model of manipulating (object), Orm implements the processing of these two methods in different periods. No one can tell which of the two methods has the deciding advantage, everything is relative, in terms of convenience of operations, in the object-oriented theoretical system.

The orm on the agileeas. NET platform stripped the definition and access of the entity, and then integrated and bonded the orm object with the accessor, that is, the following results are achieved:

1. Orm can be used to manipulate the ORM entity through the entity. Operation () or the accessor. Operation (entity.

2. Operations for separating ORM objectCodeTo keep the Code related to object definition in the orm object, define the ormaccessor attribute on the object, and call the object operation method of the orm accessor.

3. Occasionally, the interface between the orm object and the orm accessors is implemented using different accessors through code or configuration based on the interface driver.

In actual use, I send two equivalent codes:

/// <Summary>/// Output full table data/// </Summary>Public VoidDemoquery () {productlist table =NewProductlist (); ormcontext. ormaccessor. Query (table );IntCols = table. Columns. count;Foreach(Product ProductInTable. Rows ){// Do}}

Equivalent:

/// <Summary>/// Output full table data/// </Summary>Public VoidDemoquery () {productlist table =NewProductlist (); table. ormaccessor = ormcontext. ormaccessor; table. Query ();IntCols = table. Columns. count;Foreach(Product ProductInTable. Rows ){// Do
 
}}
Accessors Configuration

In the example demonstrated by Orm, I declared an ormcontext when using the ORM accesser. In the ormcontext class, I instantiated THE ORM accesser using the direct new method:

/// <Summary>/// ORM accessors./// </Summary>Public StaticIormaccessor ormaccessor {Get{If(Instance. ormaccessor =Null) {Instance. ormaccessor =NewOrmaccessor (); instance. ormaccessor. dataaccessor = dataaccessor ;}ReturnInstance. ormaccessor ;}}

From the code, we can see instance. ormaccessor =NewOrmaccessor (), so that the application business is coupled with the implementation of the accessors, instance. ormaccessor. dataaccessor = dataaccessor.

The old method to solve this problem is to use agileeas. the IOC component of the net platform to decouple the accessors. for more information about the IOC component of the net platform, see agileeas. NET platform object control reversal article.

First, replace the ormcontext class with the following code:

     Ormcontext 
  1    Static    Class  Ormcontext
2 {
3 ///   <Summary>
4 /// Orm accessors.
5 ///   </Summary>
6 Public   Static Iormaccessor ormaccessor
7 {
8 Get
9 {
10 Return Contexthelper. getcontext (). Container. getcomponentinstance ( " Ormaccessor " ) As Iormaccessor;
11 }
12 }
13 }

 

Add an application configuration file app. config to the classlib. ormdemo project and write the following information:

1 <? XML version = "1.0" encoding = "UTF-8" ?>
2 < Configuration >
3 < Configsections >
4 < Section Name = "EAS. Objects" Type = "EAS. Objects. confighandler, EAS. ioccontainer" />
5 </ Configsections >
6 < EAS. Objects >
7 < Object Name = "Dataconnection" Assembly = "EAS. Data" Type = "EAS. Data. Access. sqlclientconnection" Lifestyletype = "Singleton" >
8 < Property Name = "Connectionstring" Type = "String" Value = "Data Source = vm2003; initial catalog = EAS; user id = sa"   />
9 </ Object >
10 < Object Name = "Ormaccessor" Assembly = "EAS. Data" Type = "EAS. Data. Orm. ormaccessor" Lifestyletype = "Singleton" >
11 < Property Name = "Dbconnection" Type = "Object" Value = "Dataconnection"   />
12 </ Object >
13 <! -- <Object name = "cacheaccessor" assembly = "EAS. Data" type = "EAS. Data. Orm. cacheaccessor" lifestyletype = "Singleton">
14 </Object> -->
15 < Object Name = "Dataaccessor" Assembly = "EAS. Data" Type = "EAS. Data. Access. sqlclientaccessor" Lifestyletype = "Singleton" >
16 < Property Name = "Connection" Type = "Object" Value = "Dataconnection"   />
17 </ Object >
18 </ EAS. Objects >
19 </ Configuration >

 

Recompile and run the demo. In the next article, I will introduce the specific services that ORM cannot implement using SQL statements.

For the structure of the data table involved in this example, refer to the data table structure based on agileeas. NET platform basic library for application development-General description and data definition, for data object model definition files, documents, DDL scripts download: Workshop.

 

Link

Step by step teach you how to use the agileeas. net base class library for application development-series directory

Agileeas. NET platform development guide-series Directories

Introduction to agileeas. NET application development platform-Index

Agileeas. NET platform application development tutorial-case plan

Official website of agileeas. net

Agile Software Engineering Lab

QQ: 116773358

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.