C # 3.0 Getting Started Series (eight)-groupby operations

Source: Internet
Author: User

A different style of writing. This section is about GROUPBY operations.

GroupBy is one of the hardest to understand in all LINQ to SQL operations. Because, here and the SQL is larger. And group really can return n multiple groups.

Open VS, create a new project, and add a System.Data.Linq.dll reference. Make a map of the Northwind database and add it to the project. Creates an object for the Northwind class. Here, we want to do group statistics, we have to understand what is the group. When we started designing the product table, we wanted to leave a column called CategoryID. This field, which represents the product in this record, falls into that category. As shown in the diagram, the field is designed.

Can be a simple example, for example, when the value of CategoryID is 1 o'clock, it means that the corresponding record of the product is a beverage class. When it is 2 o'clock, it represents the condiment class. The specific representative of that category, to see the prior agreement. There is usually a special table to save this Convention. In Northwind, use the Categories table to save this Convention. The following is the record in the Catagories table.

Categories and product tables, associating relationships through CategoryID fields. That is, the meaning that the CategoryID field represents in the product table is saved in the Categories table. OK, we know the concept of grouping, let's start sorting statistics. GroupBy is one of the more difficult things to understand in all the operations of LINQ to SQL. I want to be friendly and alert you to the fields used here. Oh, the future is to be used for inheritance oh.

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.