Go to: dotext Database

Source: Internet
Author: User
Http://www.tt52.cn/blogview.asp? Logid = 178 & cateid = 3
First, let's take a look at the component Data Access Application Block, which is an optimized data access component provided by Microsoft in the form of source code. You can go
Download from Microsoft. Of course, we can also find all the code in the. Text sqlhelper. CS, adohelp. CS, and sqlserver. CS files. Both sqlhelper and adohelp contain
Sqlhelper and sqlhelperparametercache are two classes. sqlhelper is used to issue different types of commands to the database. sqlhelperparametercache is responsible
Parameter management. The sqlserver class is the implementation of the virtual class of adohelp. cs. We can see that there are many visual Virtual Methods in adohelp. CS, because the visual
Instead of abstract, these virtual members all have default implementations, so the sqlserver class is very simple. There are several other files in this directory. Their functions will be discussed later.

Next we will analyze the data access process of. text based on the categories that everyone cares about. Text.
We know that the home page has a category display, so let's see how the category of the home page is displayed.
Open template. ascx under aggsite (if you do not understand why you want to open this file, refer to this Article)
We can see that a sitemorecategory user control is used here, and then the user control is opened. We can see that it calls the link class again.
The getcategoriesbyparentid method of. Continue to trace and find and run to the dtoprovider class. dtoprovider has only a few codes, but these codes are very critical,
It has a static constructor. The advantage of a static constructor is that it will be automatically executed before we call a static member of a class!
The instance returns an idtoprovider interface, which is a clever technique,
That is to say, as long as the class implementing this interface can be returned through this method, this is when we track a lot of data access code,
There will be a reason for dtoprovider. instance (). Or something. Let's take a look at what is in idtoprovider. Wow, there are a lot of things! But they are all empty shelves!
(If you are not empty, it is also called an interface ),
We focus on analyzing the code in the constructor. dtoproviderconfiguration dtopc = config. settings. blogproviders. dtoprovider,
This is a mess! Haha, but if you use web. config, you can understand it very well. In fact, it reads the configuration from web. config by doing so many layers.
Type = "dottext. Framework. Data. datadtoprovider.
Return to the idtoprovider method getcategoriesbyparentid, because datadtoprovider implements the idtoprovider interface,
Naturally, we go to datadtoprovider to find the implementation code of this method,
Dbprovider. instance (). getcategoriesbytype (cattype, activeonly), so we have to go to the dbprovider class again.
In this class, we see code similar to dtoprovider. We found in Web. config
Type = "dottext. Framework. Data. sqldataprovider, dottext. Framework ",
Why did you go to Web. config again?
Well, what do you think of intelligently? If orcale has a Data Access Application Block (even if it doesn't exist, we can write one ourselves ),
Then we will write another orcalesqldataprovider to call it, and then call web. config
For type = "dottext. Framework. Data. orcalesqldataprovider" or something, we
Can I access the orcale database? Very correct! With such a big circle, our main purpose is to do this.
Find the implementation code of getcategoriesbytype in sqldataprovider. You can see that it executes blog_getcategoriesbytype by calling the sqlhelper function.
Stored Procedures to read the database!

Finally, let's summarize:
Config class
Read dynamic configuration information from web. config (configuration is also. Text is an important part and has the opportunity to write additional articles to study with you)

Idtoprovider, dtoprovider, datadtoprovider class Business Layer
The functional code of. Text is implemented here. The interface layer (User Control) can directly call the members here.

Idbprovider, dbprovider, and sqldataprovider data service layer
It is a bridge between the business layer and the data access layer. Because of this layer, it makes it easier to use multiple data sources.

Sqlhelper, parametercache data access layer
As described above

The table structure and stored procedure of the database should be sorted out by Dudu.

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.