Entity Framework Entity SQL (4) set Operators

Source: Internet
Author: User

Entity SQL contains many set types of data. Therefore, set operations are also important in Entity SQL. This section describes common set operators in Entity SQL.

Note that before reading this article, we first agree that the set here can contain duplicate elements, rather than the set that we usually call to not contain duplicate elements.

  • Set

Syntax: Set (colleciton)

Note: If the collection can contain repeated elements, set (Collection) will retrieve non-repeated elements in the collection.

For example, set ({, 3, 4}) returns {, 4 }.

In Entity SQL, entities and rows can be compared. Of course, as a user, you don't have to worry about how to compare objects. for entities with the same primary key, they are the same entities. For rows, the structure must be consistent, while the set cannot be compared, in other words, set ({1, 2, 3}, {1, 2, 3}) is invalid.

 

  • In

Syntax: E in Collection

Note: The in operator returns whether e is in the collection.

For example, 1 in {1, 2, 3} returns true, 1 in {-1,-2,-3}, and false.

 

  • Exists

Syntax: exists (Collection)

Description: determines whether the collection is null. If it is null, false is returned. Otherwise, true is returned.

For example, exists ({1}) returns true; exists (select V from {1, 2, 3} as V where V =-1) returns false.

 

  • Union

Syntax: collectiona Union [all] Collection

Note: Union calculates the union of two sets and removes the same elements. Union all calculates the union of two sets, but it also contains duplicate elements.

For example, {1, 2, 3} Union {2, 3} gets {1, 2, 3}, and {1, 2, 3} Union all {2, 3, 4} gets {1, 2, 3, 2, 3, 4 }.

 

  • Intersect

Syntax: collecitona intersect collectionb

Description: intersect calculates the intersection of two sets.

For example, {1, 2, 3} intersect {2, 3} gets {2, 3 }. Note: The intersection removes duplicate elements. {1, 2, 3} intersect {2, 2, 3} To get {2, 3} Instead of {2, 2, 3}

 

  • Except

Syntax: collecitona doesn t collecitonb

Note: A distinct t B indicates that the elements of the B set are subtracted from the set. In other words, it is to obtain elements in a that are not in B.

For example: {1, 2, 3} Then t {2, 3} will get {1 }.

 

  • Overlaps

Syntax: collecitona overlaps collectionb

Note: A overlaps B determines whether there is an intersection between A and B sets. If yes, true is returned. If no, false is returned. It is equivalent to exists (A intersect B ).

For example, {1, 2, 3} overlaps {3, 4} returns true, while {1, 2, 3} overlaps {4, 5} returns false.

 

  • Anyelement

Syntax: anyelement (Collection)

Description: anyelement randomly returns any element in the set.

For example, anyelement ({1, 2, 3}) may return 1, 2, or 3.

 

Summary:

This article briefly introduces some set operators in Entity SQL. All of these operators are well known. It can be listed here for your convenience.

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.