Traditional Culture Encyclopedia - Traditional stories - How to write a three-tier architecture with ORM is best illustrated by examples.
How to write a three-tier architecture with ORM is best illustrated by examples.
Generally, we put the data needed by the system in the database. The data used in the page displayed to the user is obtained by reading the database and further processing.
The data in the database is structured.
The data we need. Net programming is object-oriented.
Therefore, we need a mechanism to transform the structured data in the database into object-oriented data. So there is a common three-tier architecture in the system architecture:
Bottom layer: DAL (data access layer).
Middle: BLL (business logic layer)
Top layer: UI layer ~
In DAL, we use entity classes to encapsulate database tables:
For example, we set up an article management system. The following table is required.
[Article] [Category] [Comment]
Take [Article] as an example, it contains the following fields:
[article id][ title] [content] [added by] [added date]
The entity class corresponding to the DAL layer is [ArticleDetails].
It contains five attributes, including the following [ArticleID] [Title] .........................................................................................................................................................
We have three entity classes, corresponding to three tables in DB.
Create a class SqlArticlesProvider to complete the encapsulation of DB operation.
Usually each method encapsulates a stored procedure ~
For example, in the GetArticles(int categoryID) method.
We connect to DB, call SP, and encapsulate the returned DataReader into the entity class collection list.
BLL layer:
Classes in are called domain objects. There are [articles] [categories] [comments]
Every class here is a class in our traditional OOP.
Each object contains methods that describe its own properties and executable behavior.
UI layer, directly calling the class of BLL layer to get data, the page displayed by data binding control, etc ~
It's a little messy . . It's not enough to just say that. .
The real programming practice is much more complicated than this. .
The system with three-tier architecture is easier to maintain. Changing the underlying data storage requires only a few changes.
Therefore, it is mainly used for large and medium-sized system architecture.
Now, after the introduction of LINQ, the coding amount is also reduced. But it will take a long time to study LINQ alone.
If you don't want LINQ, there are many tool codes that can help you build some classes automatically ~
- Previous article:How to write the univariate conclusion of general linear model
- Next article:Handmade on June 1 day.
- Related articles
- Advantages of physical store grafting WeChat business.
- What is the size of the bottom of the shoe cabinet? What are the benefits of leaving blank at the bottom of the shoe cabinet?
- What to eat traditional food 24 festival season 24 festival season eat what good
- What is a brief introduction to making cups?
- What is a cloud native application? What are its characteristics?
- What is national music?
- Why are old razors so expensive?
- Bread stuffing collection and sharing
- Significance of reform and opening up
- How to use Old Beijing Mugwort Foot Patch