TechTalk Genome v4.2

Subtraction

set1 - set2
set1
An OQL expression evaluating to a Set<T> of scalar or persistent objects.
set2
An OQL expression evaluating to a Set<T> of scalar or persistent objects.

Return Value

A Set<T> containing all elements of set1 that are not contained in set2.

Remarks

The subtraction operator returns a Set<T> containing all elements of set1 that are not contained in set2. The element type of the resulting set is the most specialised common type of the element type of set1 and set2 (the current implementation restricts set1 and set2 to having the same element type, hence the element type of the resulting Set<T> is identical to the element type of both source sets).

The query engine uses cross-filtering to conduct the resulting query. Both source sets must therefore have the same element type and apply the same projections (if any). The resulting query is then defined by the query

    [projection]extentof(T)[filter1 && !filter2] 

The query

    [Name]extentof(Person)[Age >= 19] - [Name]extentof(Person)[Age >= 49] 

translates to

    SELECT Name FROM Person WHERE Age>=19 AND NOT (Age >= 49) 

Quick Reference

OQL
extentof(Animal)[Age > 10] - extentof(Animal)[Cage.Size > 100]

C#
Set<Animal> animals =
myDB.Extent<Animal>()["Age > {0}", 10] -
myDB.Extent<Animal>()["Cage.Size > {0}", 100];

SQL
SELECT * FROM Animal LEFT JOIN Cage ON Animal.CageId = Cage.Id WHERE Age < 10 AND NOT Cage.Size > 100

See Also

Set<T>.op_Subtraction | Set<T>.Subtract | OqlReference.Chapter11