A preliminary analysis of the. NET layer-3 structure page 1/4

Source: Internet
Author: User

For learning, I chose the ACCESS database + Stored Procedure method. Here I recorded my personal learning experience and notes, which may be different from those on the Internet, and my opinions may not be the same.
Why use a three-tier structure:
First of all, it should be clear that the three-layer structure does not make the system faster. In fact, it will be slower than the "single-class structure. But more and more people are using layer-3 structure for development. Why? In use, I found that the three-layer structure is very clear, a class, a file should be placed on which layer, not all put into app_data as a single class structure, resulting in structure confusion. Of course, the reason for using a three-tier structure is certainly not so superficial. It is of great significance to team development and system maintainability.

The layer-3 structure isCodeHow many times does the Code repeat?
Indeed, three-tier code needs to write a lot of code that is very idiotic and simple. For example, the model entity class. If you need an admin entity, you need to write the code like this:Copy codeThe Code is as follows: public class Admin
{
Private Int? _ Id;
Private string _ sname;
Private string _ spassword;

Public Int? ID
{
Set {_ id = value ;}
Get {return _ id ;}
}

Public String sname
{
Set {_ sname = value ;}
Get {return _ sname ;}
}

Public String spassword
{
Set {_ spassword = value ;}
Get {return _ spassword ;}
}
}

If there are multiple entities, you need to write these idiot code again. Why is it called an idiot code? Because you can write the code in a table. During a discussion with Tom, I introduced a software called "dynamic soft. Net code generator". Let the software be generated by itself! We recommend that you use this software here to reduce the amount of code that Bll, Dal, and web-layer code can be generated, but it must be fully applicable, you also need to make some modifications on your own.

Next, let's talk about the three layers I understand. First, go to Figure 1:
Web: The interface layer is actually a website.
Bll: logic processing layer.
Dal: data access layer
Dbutility: data layer base class
Model: entity class
Common: stores public functions.
Figure 2

Here we need to talk about the dbutility layer. You can see four files:
1. dbhelperoledb. CS: used for SQL statements
2. dbhelperoledbp. CS: used for Stored Procedures
3. dbhelperoledbs. CS: used for specific implementation, such as "determining existence based on conditions" and "returning the largest ID "...
4. pubconstant. CS: database connection code

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.