NHibernate three-layer structure of the common algorithm of the project

Source: Internet
Author: User

In this paper, the dynamic soft three-layer structure and the "nhibernate three-layer structure" are simply compared.

(1) Dynamic soft three-layer architecture

Newly developed ASP.NET applications, the use of dynamic soft generated three-tier architecture, easy to use. is to change the trouble. For example, to add a query data method, first in the DAL layer to add the interface method, then to the Sqlserverdal layer to add implementation code, and then to the BLL layer to add a packaging method. To add a field to a table, you have to regenerate it, or you can change it one layer at a time.

The Idal layer, which can be implemented by Oracledal or Db2dal, is designed to mask the details of data manipulation. The BLL layer is necessary to encapsulate the business processing logic. The above illustration shows the data access layer and the business logic layer, the presentation layer is the ASPX page, the call BLL gets the data, and then shows it to the user, and many times the data is displayed in the GridView.

At the time of development, two features of the BLL layer were found: processing business logic and displaying data, which could be separated. Dynamic soft generates a BLL layer class for each table in the database. And some tables do not correspond to specific business logic (such as company Information table, Personal information table), some tables need to mix other tables to complete the business logic (such as processing site login table admin, need to combine user table, role table, etc.). This can be improved. For those classes that only need to provide data and do not have to deal with business logic (such as user tables, etc.), it is easy to implement a class that is managed by a uniform, a table name (which is finally encapsulated by a view), and a query condition that returns the corresponding data. and to abstract the class of business logic. Look at the "nhibernate three-layer structure" below.

(2) NHibernate three-storey structure

NHibernate as an object-relational mapping framework, it is simple and convenient to operate the database in an object-oriented way. The following is the "NHibernate three-tier structure" used in the project:

There are nhibernate support, each model layer of entity classes can encapsulate data manipulation methods (such as save,update, etc.), BLL layer can be easily invoked. In fact, BLL mostly involve the operation of a single object (add or update, delete), this nhibernate strength, and can be in an object-oriented way to match the implementation of the business logic well.

Dataviewer is separated from the BLL layer in the original soft three-layer architecture, and is responsible for providing data to the front page. Should be grouped into the presentation layer. In this way, the level is much clearer. BLL is only responsible for handling business logic and does not provide the data presented by the foreground. Or the BLL layer is responsible for modifying the background of the database, and Dataviewer will not modify the database, only responsible for reading the database, to the foreground output combination query, pagination data.

Dataviewer does not use NHibernate hql, because HQL can lead to inefficient, use the original SQL query, do not learn new things, but also to do some query optimization. Dataviewer is best to operate the view, do not operate a specific table, easy to modify.

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.