O/R Mapping Research Report (1)

Source: Internet
Author: User
Tags xml reader microsoft website
1. Business Entity layer design scheme selection
1) Role of the business entity Layer
The general application hierarchy structure is as follows:

It can be seen that an entity layer will be added during layering. Its function is as follows:
① The data displayed is isolated from the actual storage area to ensure business independence and improve reusability.
② Transmit data between the business layer and the presentation layer. (If there is no entity layer, we need to pass each field in the table as a parameter between them. If it is modified, it will affect each layer of the program)
③ Provide greater scalability.

2) several options of the business entity layer and their advantages and disadvantages.
There are several options for implementing business entities in the. NET environment:
① Datareader be has the fastest reading speed. It is used in read-only scenarios and does not have the concept of OO.
② XML be can be converted to XML reader and dataset. Disadvantages: low performance, complicated verification, resolution, display, and sorting.
③ Generic dataset be advantages: data binding. Disadvantage: the client must obtain data through a set. There is no type, the instantiation overhead is large, and the scheduling performance is low.
④ Advantages of Typed Dataset be: the type can be checked. Disadvantage: it can only be inherited from dataset, which is inconvenient to deploy, poor scalability, high instantiation overhead, and low Scheduling Performance.
⑤ Custom be advantages: Performance Tuning and code readability. You can use a custom object class to define a good interface to hide complex problems. Disadvantages: design and development are complicated. You need to implement the curd operation on your own and implement data binding on your own, which requires a lot of work.
⑥ O/R Mapping has all the advantages of user-defined classes, and implements crud, data binding, and other operations.
2. What is o/R Mapping?
Orm, that is, object-relationl mapping, is used to map between a relational database and an object. In this way, when we operate a database, you don't need to deal with complex SQL statements, as long as you operate on objects as usual.
Let's start with O/R. The letter O originated from "object", while R came from "relational ). Objects and relational databases exist in almost all programs. In the business logic layer and user interface layer, We are object-oriented. When the object information changes, we need to save the object information in the relational database.
When you develop an application (without O/R Mapping), you may write a lot of data access layer code to save, delete, and read object information from the database. You have written many methods in the Dal to read object data, change State objects, and so on. These codes are always repeated.
If you open your recent program and look at the Dal code, you will certainly see many similar general patterns. Let's take the method of saving objects as an example. You pass in an object, add sqlparameter to the sqlcommand object, map all attributes to the object, set the commandtext attribute of sqlcommand as the stored procedure, and then run sqlcommand. This code must be repeatedly written for each object.
In addition, is there a better way? Yes. Introduce an O/R Mapping. Essentially, an O/R Mapping will generate a dal for you. It is better to use o/R Mapping than to write the Dal code by yourself. You use o/R Mapping to save, delete, and read objects. O/R Mapping is responsible for generating SQL statements. You only need to care about objects.

3. Why o/R Mapping?
1) improve learning and development efficiency and reduce development costs.
Using ORM can greatly reduce learning and development costs. The development of modern technology makes us have to keep learning. We need to learn not only object-oriented, UML, design patterns, but also SQL Server, ADO. net, dataset, datareader, and other knowledge. In actual development, what is truly valuable to customers is their unique business functions. The current situation is that we spend a lot of time writing data access and crud methods, it also takes a considerable amount of time to process bugs, such as bug search and maintenance. That is to say, in actual development, a lot of time is wasted on non-business events that do not create value at all.
After using Orm, we don't need to waste too much time on ADO. NET and SQL statements. The ORM framework has transformed the database into a familiar object. We only need to understand object-oriented development to develop database applications.

2) Simplify the code and reduce the number of bugs.
By establishing an ORM system, the program development code can be greatly reduced. After the ORM is implemented, the data layer development is relatively simple, greatly reducing the chance of errors.

3) Improve Performance
At the same time, through the implementation of cache, performance can be optimized, achieving the ORM separates the relationship between the actual data storage and the business layer, can be separately tracked for each layer, added the possibility of performance optimization.

4) isolate the data source and easily convert the database
Orm can be used to separate the business layer from data storage. Developers do not need to worry about the actual storage mode. If we need to replace the SQL Server database with an Oracle database, we only need to modify the configuration file, you do not need to modify the program.
4. Introduction to typical ORM tools
Thanks to the powerful convenience provided by Orm, many companies or individuals have provided ORM tools. There are three main approaches:
① Objectspaces provided by Microsoft
Microsoft provides objectspaces In the alpha version of vs. NET 2005. It is an ORM framework on the ADO. NET data layer. However, according to the message provided on the Microsoft website, objectspaces will not be released with vs. net2005. It may be released with winfs in 2006 (7. Therefore, it may not be available in recent projects.

② Free orm of open source code
Although the development source code in the. NET field is far inferior to that in the Java field, many people have transferred the best development source code in the Java field to the. NET platform. This includes nunit for unit testing, log4net for logs, spring. Net for AOP, and nhib.pdf for ORM framework.

The development source code is updated frequently. If you find a bug reported, they will be updated in the new version soon.
The function of source code development is not only to use, but also to use a very good architecture. When purchasing computer books, there is a saying "No coding, no reading", while open source provides the best example of how to build the architecture and how to use the mode.

There are not many documents about nhib.pdf, but I believe that with the release of its official version, there will be more and more official articles, and more users will provide their own experience on the Internet. Of course, the most direct and effective method is to read its source code. Because the internal implementation mechanism of open source code is completely transparent, its code is the best document. Its code structure is clear and its usage is more concise, which is not difficult to read.

③ Commercial ORM products of other companies
Some companies also use devexpress xpo as the orm framework for development.

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.