Post-object-oriented design, ORM, nhib.pdf

Source: Internet
Author: User
Tags what sql
Object-Oriented Design, ORM, and nhib.pdf)

The ORM design is actually an O-to-D process, that is, the data entity is finally generated by the object. however, the problem is that in traditional design, we must design a Business Object and re-design a relational object (or other storage objects, of course). This method is actually two skins, this is a repetitive process. however, since there is no object-oriented DBMS, we have to design O as a relational database and then implement it as a table.
Think about it, we usually design an object, and we need to design several attributes. Each attribute has a data type, Data Length, validity rules, and so on, the database objects correspond one by one. If only one design can be implemented. therefore, many people, including me, use the design method from D to O, that is, they first use the entity design tools provided by DBMS to design entities, then use C # To write the corresponding object.
There are two problems here. The first is that our programmers have to do both DBA and programmer jobs at the same time. The second is that business objects and Relational Tables are so closely integrated, so when we change the DBMS, We have to re-design the relational entities or use other tools for conversion. the most important thing is the follow-up work. I am afraid to think about it, because the Business Objects often change at any time. Every change, you have to modify a lot of code, at the same time, it is necessary to keep the synchronization changes of relational data tables, which is not only a large amount of work, but also a very meticulous and tedious task.
I don't know how others do it. However, this traditional design method also has a fast solution, that is, after someone designs the business object, then, use CodeSmith or other code generation tools to export business objects from the relational table and generate basic CRUD operations. yes, I have used this too. It does reduce a lot of work, and CODESMITH is the best, most scalable, and easy-to-use generation tool I have ever seen (not just code, any template that can be used to solve or even merge emails can be easily completed ). however, this only reduces the workload during development, the subsequent expansion and maintenance work, and there is no tool to help us. in addition, this design method is really good for small projects. If you can, you can also introduce data access in the enterprise library of MS to improve scalability. however, this method is still reverse. this is contrary to the popular object-oriented design method. Many people think that the object-oriented design method increases the workload. For small projects, this is true, and for small projects, I do not recommend using object-oriented design, and even I do not recommend hierarchical design because it does not exist. The purpose of hierarchical design is not to speed up development, but to increase system scalability and flexibility. using a three-tier structure and object-oriented architecture in small projects is not worth the candle. therefore, for small projects, I also combine the business logic and data access layers. therefore, for layering, it depends on the situation. as for the object-oriented design method, of course, it is an irreversible trend, and even the DBMS will face objects one day. why? I personally think this is the most natural way to follow suit. after all, computers and their technologies are invented by humans and reflect and expand the existing knowledge of humans. in fact, object-oriented is the most common expression in our life. For example, if you want to describe a person or a thing, you will define its attributes.
Back to the question, what is nhib.pdf? You can see the Help File of nhib.pdf. The structural diagram clearly shows that nhib.pdf is a bridge between business objects and data entities. in this architecture, nhibist is called Persist Object as a persistent Object. (persistent translation of this word is really not good. In the past, MS called Serialize in VC, which is called "continuous listing". These words were invented by MS anyway ). the responsibility of a persistent object is to permanently store the object, and the data entity is the form of storage. For example, an instance Org of an object named orange has the following attributes:
Color: Yellow
Weight: 250 GB
Level: Level 1
.....
With nhib.pdf, you can store it in a database table: orange to become a record.
What you need to do is:
1. Define a class to indicate orange
2. Write a configuration file that allows Nhibernate to understand and tell it what DBMS you are using, what SQL language you are using, and what connection string you are using to connect to the data source. write a ing file to associate the orange business class you write with the orange table in the DBMS.
3. Write, save, update, and delete the orange object.

It sounds good. Business Objects and data tables are like two forms of a thing. The role of nhib.pdf is to convert the expression of an object into the form of a data table, but nhib.pdf is not omnipotent, therefore, we have to write a ing file to tell Nhibernate how to convert the data. (anyone who has used SQL data transmission can think about this similar process)
So I am not manually creating this orange table? No, no. If nhib.pdf cannot generate a data table, it is not perfect. However, nhib.pdf can completely generate, modify, and delete a data table. This function is available in nhib.pdf. tools. the hbm2ddl namespace has been implemented, that is, the nhibddl can be fully implemented based on the or ing file. HBM. XML to generate the corresponding data table. you can also generate a data table that is compatible with the corresponding DBMS by modifying the configuration file.
In addition, if nhib.pdf is used, for example, one day, the supervisor asks you to say that oranges should be requested by the marketing department, the "Origin" label is often used in my experience. Similar things also involve rule changes. For example, the previous weight must be greater than 200 GB, now the requirement must be greater than 250 GB, similar to the rule I change (this is called a constraint in DBMS)

For the scenario described above, you need to add a new property: Origin of org for the business object, and make a rule judgment for its set property configurator, if the rule is not correct, an exception is thrown and processed. at the same time, it is the ing file of this object. HBM. add a new property ing in XML. Finally, assign a value to the property of "Origin" where the object is used. everything OK

However, if you do not design with Orm, but separate the Business Objects and data entities as I did before, then write your own business object operation class to complete the operations on the data entity (this is very common, like the petshop of MS, This method also has the Face Image Service and the face image object, the difference is that, service-oriented is a class that defines a static method. The object attribute to be operated is passed as a parameter. The object-oriented method needs to write a business object and define attributes for it, then define the method to implement crud. the two methods have their own merits. The previous method does not need to instantiate an object. Because there is basically no business object, the "attribute" of the Business Object is passed in and processed as parameters, saving resources. however, the latter method is more flexible.) in any case, in this case, you must be extremely careful when changing the business objects or rules, because you may want to do the following:
1. Modify the data table to conform to the new business object.
2. Modify the Business Object (if object-oriented instead of service is used)
3. Modify parameters (if service-oriented, you need to add or remove parameters passed in by each static method)

You must ensure that every small change is completely consistent between the business object and the data entity. Otherwise, a small error may cause a problem.

Like the hierarchical design and object-oriented design above, Orm is facing various disputes from its appearance to the present. However, this is completely normal, because the angle and level of the problem are different, in addition, there are different requirements. Therefore, you do not need to doubt the necessity of ORM. For useful people, it is a tool and a weapon. For those who do not need it for the time being, it may be chicken ribs. however, at least from my experience, I think it actually solves my troubles. This is the most important thing.

In addition, it should be noted that ORM is not equal to nhib.pdf, but it is so famous that people think of it when it comes to ORM. In fact, it is not a new thing, it is a JAVA-based Hibernate framework transplanted. NET implementation, in fact, many people have written the ORM framework, some are lightweight, such as Smart Persist Layer, but it is still far from being compared with nhibist. in addition, for a long time, JAVA and. the two camps of NET both despise each other and I think it is not appropriate because nhib.pdf is a good example. mutual absorption is the most important thing. java has the following advantages. NET deficiency ,. the advantage of NET is not. NET? In the past, many JAVA joke. NET programmers, there is a very important reason, as some old bird netizens said: the various frameworks under JAVA readily refer to the force-less classics, such as Hibernate, such as Spring, ,. NET is too small in this regard. MS draws a beautiful blueprint, but there are too few blue-powered buildings. Therefore, we need to learn from JAVA. even if we port it like nhib.pdf, it is a kind of progress.

At the same time, it should be noted that nhib.pdf is not a software, and many people misunderstand that it is a code generation tool similar to MyGenerator. In fact, it is not a persistence framework. many beginners will be confused when they hear about the framework. The framework is a solution proposed to solve a certain problem or scenario. You can understand it in this way and add it in the box, it must have completely solved some transaction. of course, there are also lightweight and heavyweight points.

Therefore, a complete project using nhib.pdf can be divided into the following parts:
Nhib.pdf
Business Object
Business Object ing Configuration
Other business operations
Nhib.pdf Configuration
Data entity

The principle of nhib.pdf is to read the configuration file, connect to the corresponding database, convert the business object into a data entity based on the Business Object and Business Object ing configuration, and save
Note:
1. The data source (the administrator of the data entity) is configurable. Currently, nhib.pdf supports ORACLE, SQL SERVER, MYSQL SERVER, FIREBIRD, and so on. It is very powerful.
2. It doesn't mean that nhib.pdf is used to discard ADO. NET and so on. nhib.pdf still supports you to use them to access object objects.

Okay, so far, it's an introduction. It's written to friends who are still unfamiliar with ORM and nhib.pdf.

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.