[Original]. Net distributed architecture development practice III. In-depth thoughts on data access

Source: Internet
Author: User

. NetDistributed architecture development practices 3 In-depth thoughts on data access

 

First of all, I would like to thank my friends in the gardenArticleThank you for your support. I hope this series of articles will help you a little. Thank you again.

 

You may want to ask whenCodeThe code will surely come out. I don't want to throw a lot of code as soon as I come up, and then I will explain that the design of the architecture is in the process of thinking. When I think about it, the code will come to the fore.

 

The previous article tells you how,RichardThis article further considers some of the sketch.

 

The topics in this article are as follows:

1.Where are some issues with sketch?

2.Review previous project data layer issues

3.A breakthrough in thinking

4.Let's look back at the data access layer.

 

Links to articles:

[Original]. Net distributed architecture development practices

[Original]. Net distributed architecture development practice Draft II Design

[Original]. Net distributed architecture development practice III. In-depth thoughts on data access

[Original]. Net distributed architecture development practices 4 build a bridge between ideal and implementation (previous article)

[Original]. Net distributed architecture development practice 5 framework Improvement

[Original]. Net business framework development practices six Dal Reconstruction

[Original]. Net business framework development practices-a preliminary idea of the seven business Layers

[Original]. Net business framework development practices-eight business layer ing selection policies

[Original]. Net business framework development practices 9 mapping attribute principles and verification rules implementation strategies

[Original]. Net business framework development practices in the first phase of the 10 Summary, a simple introduction, the water goes by the way (previous article)

[Original]. Net business framework development practices in the first phase of the 10 Summary, a simple and easy to understand (later)

 

1.Where are some issues with sketch?

 

WhenRichardAfter drawing the grass, I thought of another problem:DalWhether or not the interface layer provided between data layers should beServices Interface. In fact, this interface layer is commonInterfaceLayer orServices Interface,RichardI can't decide, because I had to change this interface layerServices InterfaceBecause the data source provider(Service agent)That piece gave him "inspiration"-data sources can be remotely usedServices. Based on this ideaRichardIt is also taken into consideration: Maybe, the current design of thisDalWhich day will it serve to others?ProgramThe provision of data is not fixed.

 

Although this problem is not so important for the momentRichardCannot convince yourself which interface layer to use(Maybe it isRichardThe character of this person is related. You must give yourself a reason to persuade yourself, but this reason cannot just confuse yourself.).

 

RichardI think that when I was developing a project, I did use the services provided by other companies as data sources. Although the call was just a simple operation of querying, adding, deleting, and modifying, many procedures have been defined by the service provider. For example, when sending a batch of goods,RichardOnly oneCreateproduct)Method, but there are a lot of things done on the server side: Calculate inventory, generate orders, and select the goods supplier. In this case, ifRichardSetDalAddServices InterfaceLayer, thenDalOr other layers must provide many logical operations, not necessarily logical operations, but also data format authentication and identity authentication.

 

If this is the case, there will be a lot of data layer operations and a lot of logic. These logics areBllIs a better choice, think of here,RichardIt seems to start to understand:Services InterfaceLayer onBllLayer. In this way, we can make full useBll. SoDalThe interface layer above decides to use a common interface.

 

2.Review previous project data layer issues

RichardAt the data layerDalIt took a lot of time to think about it, for a reason. In the previous project, the design of the data layer was very bloated andRichardIt seems that these codes can already be written in a common way, and there is no need to write such complex code.

For exampleEmployeedalThere are the following methods:

 

Code

Public Employee getemployeebyid ( String Employeeid );
Public Emplpyee getemployeebyname ( String Employename );
Public   String Getemployeepositionbyid ( String Employeeid );
Public   Int Getemployeecount ();

 

There is no error in this writing. But one thing caused RichardThinking:DalClass, many methods are basically the query method, andAdd, update, deleteIn manyDalThe forms in the class are relatively uniform, especially in the useLINQ, Entity FrameworkThen, all data entity classesAdd,Update, deleteThe methods are almost the same, as inLINQAvailable inDatacontext. gettable <t> (). insertonsubmit (entity)Method to insert any data entity class.

 

However, it is difficult to unify the query methods based on these different conditions.DalYou must implement your own specific query methods. HoweverRichardI think it is possible to unify these methods, or even achieve the "same effect", with this idea.RichardStart to make a lot of attempts.

 

3.A breakthrough in thinking

RichardI tried my best to search for solutions in my mind. I also read the books I have downloaded and bought to see if they are related to data queries, as long as you see the chapter with the word "query,RichardYou will not miss it. See also. NetA well-known Open SourceFrameworkDesign Idea.

 

The prompt is:Fowler <Enterprise Application Architecture Model>The query object mentioned in the book.(Query object),RichardAfter reading this document, the first response is: it is really good, but it is too abstract. No examples are provided.

 

Actually beforeRichardWhen reading this book, I think the height of the book is too high,RichardSeveral times of study, are all hit. Therefore, the result isRichardThis book is awesome, but I still want to win it one day. Now there are some solutions and implementations for querying objects in the book,RichardIt's hard.

 

RichardI think that many things are not done only when all your conditions are met. Things often happen when you are not ready. Everything has a beginning, the same is true for architecture design. When designing an architecture, it does not mean that you have mastered all the technologies completely and are perfect. It must have been a process of getting started. It may be a lot of loopholes at the beginning of the design, but the closeness of thinking is also slowly developed.

 

When thinking, you can look at the problem from a higher perspective.(Now I am a developer, but the developer can think like this during design and development: If I am a architect,What will I do?)The high level of thinking goes up, and the opportunity will be easy when it comes.

 

RichardStart to understand the query object again. In fact, the query object is hidden to a certain extent.SQLThe query object is an application of the interpreter mode.,In fact, the query object must be interpretedSQLStatement to be executed in the database(No matter how the query object is operated step by step in the intermediate process, because the database only knowsSQLSo the query object is still generated.SQLStatement).

 

The main purpose of a query object is to allow the customer program to construct various queries, and the query uses all the attributes related to the business class. This means that the customer program does not need to understand the table name and column name of the database. The most direct advantage of this approach is that business developers do not need to know the database structure.

 

In addition, if the query object is designed as an interface, the flexibility is even greater. For example, designIQUERYThen, there are two implementations in the architecture.IQUERYInterface query object, suchLinqquery, efquery,The two specific query objects will be interpretedLINQAndEntity FrameworkCan identify the statement, and then passLINQAndEntity FrameworkTo perform data operations. In a program, you can configure the query object and the data access technology.

 

More and more ideasRichardIn my mind, and the problems that come with it also began to pile up. The basic idea is yes, but it is another thing to implement it. How to clarify these thoughts, how to turn these clear thoughts into code implementation, and this has becomeRichardThe most practical problems.

 

But in any case, there has been a little progress. I remember that my mind was blank when I first thought about it. Now I think one after another, and I have improved my thinking.RichardI feel a little pleased.

 

4.Let's look back at the data access layer.

With the above ideas,RichardReviewDal, Began to find:DalIn fact, it is just a place to access data and operation data.Dal. Now, the design of the data layer can basically be implemented, and it can be "Same as should be done", regardlessBllInDalYou can use the four methods for adding, deleting, querying, and modifying layers.

 

This article is here. Thank you!

Next:. NetDistributed architecture development practices 4 Build a bridge between ideal and implementation

 

The copyright is owned by Xiaoyang and the blog Park. for reprinting, indicate the source to the author.

Http://www.cnblogs.com/yanyangtian

 

 

 

 

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.