Query Statement 5

Source: Internet
Author: User

JOIN clause:

The join clause can be used to associate elements from different source sequences without direct relationships in the object model. The only requirement is that the elements in each source need to share a value that can be compared to determine whether it is equal.

Three types of links:

 

 

Left Outer Join: returns each element of the first set, regardless of whether the element has any related element in the second set. You can call DefaultIfEmpty to execute the left Outer Join by calling DefaultIfEmpty to the result of grouping join. Call DefaultIfEmpty to execute the left Outer Join. To execute external links, you must process and judge null.

Var temLefJoin = from person in people
Join pet in pets
On person equals pet. Owner into hj
From tempSub in hj. DefaultIfEmpty ()
Select new {PersoName = person. FirstName + person. LastName, petName = (tempSub = null? String. Empty: tempSub. Name )};

 

 

Multi-join: You can splice any number of Join Operations to perform multi-Join Operations.

Var tempList = from cat in cats
Join dog in dogs
On cat. Owner
Equals dog. Owner
Join person in people
On cat. Owner equals person
Select new {PesonName = person. FirstName + person. LastName, CatName = cat. Name, dogName = dog. Name };

 

Review key connection:

/// Determine the persons, even if the student is an employee

Var tempPersons = from employee in employees
Join student in students
On new {employee. FirstName, employee. LastName}
Equals new {student. FirstName, student. LastName}
Select new {Name = student. FirstName + "" + student. LastName };

Let clause:

In a query expression, it is sometimes useful to store the results of a subexpression, which can be used in subsequent clauses. You can use the let keyword to create a new range variable and initialize the variable with the result of your provided expression. Once this range variable is initialized with a value, it cannot be used to store other values. However, if the range variable stores the queryable type, you can query it.

Var earlyBirdQuery =
From sentence in strings
Let words = sentence. Split ('')
From word in words
Let w = word. ToLower ()
Where w [0] = 'A' | w [0] = 'E'
| W [0] = 'I' | w [0] = 'O'
| W [0] = 'U'
Select word;

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.