ASP. NET unlimited classification implementation instance (depth field)

Source: Internet
Author: User

The red arrow in is the parent class and belongs to the root directory level.

The following fields are: Id parent ID type name deep sorting

There is nothing to explain about the first three fields. Anyone who has done an unlimited classification design should be clear about it.

The sorting field ID of the 5th fields: the 23 sorting field ID of 43 represents the 23 root directory in this table.

The 23,01 under 23 indicates that it is a level-2 classification, with 01st entries under 23 and 99 categories supported.

What is special about me is that I have an extra depth field. You can view the data,

The depth field of ID: 40 is also 40, and the depth field of ID: 43 is also 43.

Their sub-classes are followed by "," and their own IDs.

The depth field of level 2 subclass is (parent class ID, self ID), and so on. Level 3 Classification depth is (total parent class ID, parent class ID, and Self ID ), not to mention it later.

Here, we can look at the figure above, because my websiteProgram, Only two levels of classification.

Of course, there is also the "," you can use your favorite character. You can use "|" "-" "_", but we recommend that you have a character.

The reason is that it is easy to separate and intuitive in the program. You can modify the classification data on your own in the database (because the website classification is rarely changed, you can add all types to the database for the first time)

Speaking of this, let's talk about the functions and benefits of this field. At first glance, this field seems to be a waste of resources. Let me explain it in detail:

Industry portal websites often have this requirement. You need to find all subcategories under a specific category. If this field is not available,

The SQL statement should take a long time to identify all the following word categories, or use recursion: locate all Level 2 categories based on Level 1 parent class id -- locate all Level 3 categories based on Level 2 Category ID. If there is a Level 2 category, this recursive efficiency can be imagined.

If you have this field (and the data has been properly matched), everything will be much more beautiful, so that you can easily find all the sub-classes under a certain category. The following figure shows:

Do you understand it? You only need to add the conditions. For the depth like '000000', note that % must be followed
In this way, we can find out all the sub-classes including myself. If we don't need to bring myself, we only need to find all the sub-classes under myself. It is very simple, and the depth is like '40 ,'
You only need to replace "%" with your own delimiter (that is, I emphasize the role of the delimiter ).

Is this easy, and if order by nt_orderby is followed, will it automatically sort the order based on the Sort data of your database?

In conclusion, although this field is easy to use, the logic program for adding updates is often increased while adding updated classified data. However, for the sake of performance and convenience of SQL statements, all of this is worthwhile.For a detailed demonstration,Click here

Related Article

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.