How to use Linq data packet
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!