LINQ to SQL statements concat/union/intersect/except--2017 February 22

Source: Internet
Author: User

Concat/union/intersect/except operation

Applicable scenario: Handling of two collections, such as append, merge, take same item, intersect item, and so on.

Concat (Connection)

Note: Connecting different collections does not automatically filter the same items;

1. Simple form:
Q = (         db. Customers         c.phone        ). Concat (         db. Customers         c.fax        ). Concat (         db. Employees         e.homephone        );

Statement description: Returns the phone and fax for all consumers and employees.

2. Composite form:
Q = (         db. Customers         Select New         {             Name = c.companyname,             c.phone         }        ). Concat (         db. Employees         Select New         {             + e.lastname,             Phone = E.homephone         }        );

Statement Description: Returns the name and phone number of all consumers and employees.

Union (Consolidated)

Description: Connect different collections to automatically filter the same items; That is, merging two collections to filter the same items.

Q = (         db. Customers         c.country        ). Union (         db. Employees         e.country        );

Statement Description: Query the country where the customer and the employee are located.

Intersect (intersect)

Description: Take intersect item; delay. That is, get the same item (intersection) of different sets. That is, it iterates through the first collection, finds all the unique elements, then iterates through the second set and compares each element to the element found earlier, returning all elements that appear within the two collection.

Q = (         db. Customers         c.country        ). Intersect (         db. Employees         e.country        );

Statement Description: Query the country where the customer and the employee are in.

Except (with non)

Description: Exclude intersecting items; That is, you remove the same item from a collection as in another collection. Iterates through the first collection, finds all the unique elements, and then iterates through the second collection, returning all the elements in the second collection that do not appear in the preceding collection of elements.

Q = (         db. Customers         c.country        ). Except (         db. Employees         e.country        );

Statement Description: Query the customer and staff of different countries.

Series Article Navigation:

Where is the LINQ to SQL statement (1)

Select/distinct of LINQ to SQL statements (2)

Count/sum/min/max/avg of LINQ to SQL statements (3)

Join of LINQ to SQL statements (4)

Order by of the LINQ to SQL statement (5)

Group by/having for LINQ to SQL statements (6)

Exists/in/any/all/contains of LINQ to SQL statements (7)

Concat/union/intersect/except of LINQ to SQL statements (8)

LINQ to SQL statements (9) Top/bottom and paging and sqlmethods

Insert of LINQ to SQL statement (10)

Update for LINQ to SQL statements (11)

Delete and use attach of LINQ to SQL statements (12)

Open concurrency control and transactions for LINQ to SQL statements (13)

Null semantics and datetime for LINQ to SQL statements (14)

String for LINQ to SQL statement (15)

Object identifiers for LINQ to SQL statements (16)

Object loading for LINQ to SQL statements (17)

The conversion of an operator to a LINQ to SQL statement (18)

LINQ to SQL statement (19) ADO. LINQ to SQL

The stored procedure for LINQ to SQL statements (20)

User-defined functions for LINQ to SQL statements (21)

DataContext of LINQ to SQL statements (22)

Dynamic query of LINQ to SQL statements (23)

View of LINQ to SQL statements (24)

Inheritance of LINQ to SQL statements (25)

Introduction to LINQ

Adsfsaf

LINQ to SQL statements concat/union/intersect/except--2017 February 22

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.