In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you the "sample analysis of Nhibernate and code generation", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Nhibernate and code generation sample analysis" this article.
Before giving you a detailed introduction to Nhibernate, let's first learn about ORM and code generation, and then give a comprehensive introduction to Nhibernate.
Originally has been using code generation, including CodeSmith and CodeMatic. Recently, I plan to learn Nhibernate systematically. After a simple exploration, I found that ORM and code generation are really unique.
This article focuses on comparing the advantages and disadvantages of ORM and code generation, so that they can compete with each other, in order to identify fake things, retain the real things, so that the two can complement each other. In order to better improve the efficiency of development.
This article compares ORM (with NHibernate as the O camp) and code generation (with CodeMatic as the C camp) from the following three levels:
1. In view of the similarities and differences between the two databases on the architectural level.
two。 In view of the similarities and differences in the use and configuration of the two applications.
3. Aiming at the similarities and differences of support for change and complexity between business logic and business logic.
The following is specific for these three levels to do a specific analysis, these analyses are derived from some of their own development experience and experience, some are correct, some also have problems of one kind or another. If I write it, all I hope is to throw a brick to attract jade and get the help and support of more friends and brothers.
1. In view of the similarities and differences between the two databases on the architectural level
ORM is aimed at the top-down relationship of the database, which means that ORM does not depend on the database. He can completely liberate the programmer from the relational database, and the programmer needs to take good care of the persistent object passed to nhibernate. This looks more OO, while code generation is just the opposite, which depends on a relational database. It summarizes some commonalities of database operations and automatically generates code that would otherwise need to be handwritten by programmers. From the perspective of OO, the process of code generation does not embody the idea of OO, but according to some logic of templates or software authors. The generated code may have good OO ideas. For databases, ORM is top-down and code generation is bottom-up. The two are going in the opposite direction.
two。 In view of the similarities and differences in the use and configuration of the two applications
The use of nhinernate requires adding references to nhibernate.dll and other related dll on the original system, but code generation is not. Code generation is generated in another software by specifying the database to generate files used to operate the database, which can only be used normally when these files are added to the project. The biggest headache for nhibernate is the writing of configuration and mapping files. And code generation, if you need to complete complex logic and custom business, you need to write CodeSmith and other software templates, the preparation of these templates is not a simple thing. From the use and configuration point of view, the similarities and differences between the two lies in the use method, reference method, configuration file nhibernate system needs to add related references, need to write a large number of configuration and mapping files. You don't need to add references outside the codematic system, you don't need to configure when the business is simple, and you need to write a custom template bbs.j2mehome.com when complex.
3. In view of the similarities and differences of support for change and complexity between business logic and business logic
If there is an original User table, the table has been running for some time. But now you need to add a field that can be null to the User table: BirthDay. How should each respond to this requirement?
Database changes, configuration changes, code changes nhibernate do not need to add mapping to BirthDay to change the User class in the mapping file, add properties BirthDaycodematic need to add a BirthDay field to the User table, do not need to change * * in use, you need to regenerate the code from the data layer to the business logic layer, if there are previous changes, you need to manually add BirthDay to the relevant code for single table operation, both of which are relatively simple But how expressive are the two when the business becomes complex? For example, there is now an application environment that calculates and maintains employees and salaries:
1. List all the staff.
two。 List the salary information of an employee for a certain month.
3. Count the total salary of an employee in the second quarter.
4. Calculate the total salary paid by the company to employees in the first half of the year. This includes the salaries of those who have left their jobs.
In such an application environment, it is not necessary to create a manual User,Salary business object to discuss how to deal with the data table business object configuration file business object using nhibernate. You need to write a configuration file to indicate the master-slave relationship of business objects. When there is a difference and association between the two, the built-in support for codematic requires the creation of User and Salary tables, and specifies that when the master and slave do not need to generate association and encirclement, the underlying and upper business codes of the data need to be changed manually.
To sum up, ORM and code generation have their own advantages, but considering ORM is more in line with the taste of OO, while code generation is more flexible and can be applied to other aspects in addition to database operations. For example, generate the mapping files needed by nhibernate, etc. Coupled with the original URM and data modeling, several common, the development efficiency will be greatly improved.
The above is all the content of the article "sample Analysis of Nhibernate and Code Generation". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.