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.
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.
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.
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.
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 }.
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}
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 }.
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.
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.