Click here to Skip to main content
15,885,767 members
Articles / Programming Languages / C#

CYQ.Data from entry to abandon ORM Series: Opening: Automation Framework programming thinking

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
3 Jul 2016CPOL9 min read 7.3K   1  
This is a presentation of a cyq.data ORM article.

Introduction

This is a presentation of a cyq.data ORM article, and this is my first post。

Background

With free CYQ.Data began to return after use, we found that users of the more agitated mood, in order to maintain this constant sexual excitement, so I had the idea of open source.

Also, since the frame after this 5--6 years of continuous evolution, previously issued earlier tutorial has been too far behind, including the use, and related presentations are easily misleading.

To this end, I intend to write a series again to introduce the latest version, so that everyone transition from traditional ORM framework program to automate programming type of thinking (self-made word).

So: This new series name is called: CYQ.Data from entry to abandon ORM series

What is: CYQ.Data

1: It is an ORM framework.

2: It is a data-tier component.

3: It is a set of tools library.

Let's look at a map:

As can be seen from the above chart, it is not just a ORM, also comes with a number of functions.

therefore:

Write log: you no longer need: Log4net.dll

Operating Json: you no longer need newtonjson.dll

Distributed cache: you no longer need Memcached.ClientLibrary.dll

The current framework is only 340K, subsequent versions will not confuse the work, the volume will be smaller.

传统ORM的发展过程:

Look at a cookie-cutter development trends:

Search .NET open source system in China: ORM, there are number of about 110, found in the .NET system in CodeProject: There ORM, number about 530.

After a lot of view, it is easy to find, ORM market are almost the same, the only difference:

That is, a custom query syntax, each in their own tricks to play, and must play a different, and everyone else a kind, shows no sense of superiority.

At the same time such a wide range of query syntax sugar does not make sense, but also a waste of time many developers, because the cost of learning is to look at a book or a series from entry to the master.

Comprehensive view, can escape this trend, there are wood! Description is made ORM routine, innovation is the need of art cells.

Once, I also have a very simple and traditional ORM called XQData:

I made in 2009, he was found lying on the hard disk now, willful share on the open source ORM you have not made too little friends use when getting started guide.

XQData source (SVN Download) Address: http: //code.taobao.org/svn/cyqopen/trunk/XQData

CYQ.Data automation framework of thinking:

In earlier versions of CYQ.Data (specifically not say how early), and compared to traditional brick and mortar type ORM, in addition to eclectic, looks a little wave, encouragement and concern value, it does not feel cool with where .

With the formation of automation framework of thinking, after years of improvement, the gap between now and the entity type ORM longer on the same level.

Code written in a way to look at entity type ORM: the entity inherited from CYQ.Data.Orm.OrmBase

 using (Users u = new Users())
{
            u.Name = "cyqdata";
            u.TypeID = Request["typeid"];
            //....
            u.Insert();
 }

It looks very simple is not it? Indeed, but it was too immobilized, not smart enough to write upon death, the coupling is perfect for each pair.

Why do I recommend using MAction? Because it has automation framework of thinking:

See the following code:

using (MAction action = new MAction(TableNames.Users))
{
    action.Insert(true);//This intermediate is no single assignment process
}

Compared to what code can see the advantages of coming:

1: less code, and not the middle of the assignment process;

2: No database fields and properties and rely on: whether you modify the front end interface, or modify the database, the code behind is not adjusted;

If the increase in operations and transaction switching table, this time to have two advantages:

1: Entity ORM: only use a distributed transaction that contains a snippet, a link can not be reused.

2: MAction: you can use local transactions, you can reuse the link.

MAction above code, there is a dependence TableNames.Users table, if it becomes the parameters that you will not find the same sky:

using (MAction action = new MAction(ParameterTableName))
{
     action.Insert(true);
}

So two lines of code, you find that totally decoupled and databases and interfaces.

Here you will find that it is this entity type ORM framework and not a place Level:

1: Because it decouples data layer and UI layer in the true sense.

2: Because it is based on automated programming framework of thinking, there is no longer a process of a property assignment.

See here, come back to look at the framework of the open-source ASP.NET Aries AjaxBase, you can understand why the background always so point code can handle any automatic processing tables and data on:

The following method requires only the front page only needs to pass a table name (+ corresponding data):

If further, the name of the configuration table in the database Url menu field, then the formation of an automated page:

These automatic automation framework programming thinking, ORM entities are not available, can only play a minor entity ORM interface for a bunch of codes knock a bunch of code.

看一个API接口设计:

Let's say a App projects, Android and IOS, they all need to call back API, this time, how do you design?

To not move, waiting for App Manager product to interface prototypes are finalized, then what elements needed for the App interface, and development App development engineers talk about, and then write a method for the request?

After all, you want to know which table to read, check what data, so that you can only passively? Each additional page or a function, you have to go back to write a bunch of business logic code, and then carry out the FBI?

Tired, is not it?

Look at the direct use of this framework, your design process will become how simple, elegant and abstract thinking:

Interface core code:

using (MAction action = new MAction(tableName))
{
     action.Select(pageIndex, pageSize,where).ToJson();
}

Next, you want to design are:

1: The App will be a good client request format parameters: {key: 'xx', pageindex: 1, pagesize: 10, wherekey: 'xxxx'}

2: Mapping table name into the database (Key, Value), App only pass Key When requested name

3: According to the actual business, where good construction conditions.

Several more such universal interface design, to give app developers will be able to see what are the advantages:

1: You can reduce a lot of communication costs.

2: API is designed to be versatile, and reduce the amount of code that can be configured to follow simple maintenance.

3: In the beginning you can start, do not need to wait until then to start App prototype hands.

4: Even if there are tables, long into what can advance no matter late to database configuration.

5: After a realization, for the company to change business change project can also be used, because your design and specific business are decoupled.

Imagine replaced entity ORM, you are not to have a database in advance, generate a bunch of solid bar, and then continued to New specific examples of it, the limitations of thinking can only be limited to the specific business.

Framework of abstract thinking and where conditions are derived intelligence

Look at a map:

Common data table for CRUD operations, can be seen from the figure, the final frame abstract two core arguments:

Table + where conditions:

Once I have thought about syntactic sugar, whether to Where this piece is designed to:.... .Select (...) Where (...) Having (...) GroupBy (...) OrderBy (.. .) ...

Later still insist on holding early Native Heart:

1: developers no learning costs.

2: maintain a youthful creativity framework.

3: with automation framework thinking.

Syntactic sugar disadvantages:

1: Framework itself complex designed to increase the degree of heterozygosity.

2: user learning costs, increasing the use of complexity.

3: Not suitable for automatic extension: Design has become the expression, unable to dynamically construct the query dynamically based on certain conditions and Key table! Specific examples of suitable only for business and are not suitable for automatic programming.

Through intelligent derivation removed (because the primary key table different tables are not the same), the smart generation is derived that allows the programmer to pass over the main concern value, rather than focus on any specific named primary key primary key name parameter.

If the value is the "1,2,3" This multi-value separated by commas, the framework will automatically turn into a derivation of the primary key in (1,2,3) condition.

Look at the two codes: the left is still a relatively complete condition where the right derivation type is intelligent programming.

Note: the same traditional values, but what we want is UserName, not a primary key, the system can be derived?

This time the system will be based on the type of value, primary key, unique key equivalent type of comprehensive analysis, the value should be used to construct where the primary key or unique key.

(PS: The only key derivation yesterday to complete the function, so that only the latest version only.)

Because intelligent frame derivation function, shielding field differences, so that users only need to pay attention to traditional values. It also allows you to automate the programming framework for thinking important functions.

Automation Batch Programming:

See a map: DataTable: It and various types of data directly with each other Batch conversion:

DataTable is one of the core framework, there is an exclusive presentation on its articles.
Of course, Table Construction, often based on the line, so look at a map: MDataRow (which is the core of a single row of data)

In fact, precisely because DataRow opened the single-line batch data come and go, so it created a batch processing MDataTable of multiple rows of data.
In fact MDataRow achieve the core layer, but it is relatively low-key.

to sum up:

When using programming framework, you will find more concerned about is: the flow of data, and how to build configuration parameters for the abstract system.

  In most programming time, in addition to specific fields meaning the need for specific attention, most of them based automated programming thinking, data flow thinking.

  The early series: there is no such programming thinking, inevitably looked after each presentation will be a kind of a sense of violation.

  Now the system: automation framework programming thinking, but also a high degree of customer loyalty in love with reason, especially after free.

  Of course, for this series of follow-up will be re-written tutorials, tutorials and source code will be synchronized to SVN, so stay tuned.

PS:If you want to try to use it,you can search cyqdata on nuget.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --