TechTalk Genome v4.2

Retrieving Tabular Resultsets

[ [alias:] new object[] {expression-1,expression-2, ... expression-n} ]set
alias
An identifier used to alias the candidate element of set. If alias is specified, the this keyword refers to the candidate element declared in any outer scope (the semantics of the this keyword are not altered when an explicit alias is used). If omitted, the this keyword can be used to refer to the candidate element of set.
expression-1, expression-2, ... expression-n
OQL implicit functions executed on candidate elements of set, returning a scalar values or persistent objects. The return values of the expressions are used to initialise an object array for each row in the resulting Set´1. alias (if declared) can be used to refer to the candidate element of set. Identifiers declared in outer scopes of the expression can be freely used within expression-i.
set
An OQL expression returning a Set<T> of scalars or persistent objects.

Remarks

This construct can be used to retrieve tabular resultsets from the database. The expressions specified in the array initializer can be scalar, persistent or nested array expressions.

The element type of the set projected with this construct is object[] that can be indexed on the client code that processes the elements of the set. Further projection, filtering or sorting operations are not supported on the projected set.

Quick Reference

OQL
[new object[] { Name, Sql.Avg([Age]Inhabitants) }]extentof(Animal)

C#
Set<object[]> animalInfo = myDB.Extent<Animal>().
Select<object[]>("new object[] { Name, Sql.Avg([Age]Inhabitants) }");

SQL
SELECT a.Name, AVG(SELECT c.Age FROM Cage c WHERE c.Id = a.CageId) FROM Animal a

Examples

Set<object[]> s = dd.Extent<Employee>().Select<object[]>("new object[] { this, Reports.Count }");
foreach (object[] row in s) 
{
    Employee e = (Employee)row[0];
    Console.WriteLine("{0} {1}: {2} reports", e.FirstName, e.LastName, row[1]);
}
                
Other examples:
    [new object[] { this, Name, Cage.Name, Cage.Keepers.Count }]extentof(Animal)
    [new object[] { new object[] { x, y }, z }]...
    [new object[] 
        { 
            GetSoldQuantity(year, "S"), 
            GetSoldQuantity(year, "L"), 
            GetSoldQuantity(year, "XL") 
        }
    ]extentof(Product)
Where Product.GetSoldQuantity(year, size) could be mapped as follows:
    Sql.Sum([Qty]OrderLineItems[Size == size && Order.YearOrdered == year])

See Also

PredictiveCacheManager | Projection | OqlReference.Chapter5