Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Linq data packet

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use Linq data packet". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Linq data packets.

Linq data packet (GROUP BY)

Groups the elements in the query results based on one or more fields of the element. For example: Linq data grouping of students by grade (class year):

Dim studentsByYear = From student In students _ Select student _ Group By year = student.Year _ Into Classes = Group

The program that outputs the results:

For Each yearGroup In studentsByYear Console.WriteLine (vbCrLf & "Year:" & yearGroup.year) For Each student In yearGroup.Classes Console.WriteLine ("& student.Last &", "& student.First) Next Next

Full syntax:

Group [listField1 [, listField2 [...]] By keyExp1 [, keyExp2 [...]] Into aggregateList

◆ listField1, listField2: optional. One or more fields of query variables that explicitly identify the fields to be included in the grouping results. If no fields are specified, all fields of the query variable are included in the grouping results.

◆ keyExp1: required. An expression that identifies the key used to determine the grouping of elements. You can specify multiple keys to specify a key combination.

◆ keyExp2: optional. One or more additional keys, combined with keyExp1, to create a key combination.

◆ aggregateList: required. One or more expressions that identify how groups are aggregated. To identify a member name for the grouping result, use the Group keyword, which can be: Into Group

Linq data packets for example:

Dim * layer _ grouping = From cust In db.Customers _ Group By country = cust.Country _ Into layer 2 _ grouping element = Group, Count () _ Order By national For Each A grouping In * layer _ grouping Console.WriteLine (A packet. Country & "(" & A grouping .Count & ") For Each An element In A grouping. The second layer _ grouping element Console.WriteLine (vbTab + An element .CompanyName + "," + An element .ContactName) Next Next so far, I believe you have a deeper understanding of "how to use Linq data packets". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report