TechTalk Genome v4.2

Retrieving Transient Objects

[ [alias:] new transient type ( expression-1,expression-2, ... expression-n) ]set
or
[ [alias:] new transient type {property-1 = expression-1,property-2 = expression-2, ... property-n = 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 scalar values or persistent objects.
The return values of the expresssions are used to initialise an object of the specified transient type for each row in the resulting Set<T>. Depending on the syntax used, initialisation occurs using the constructor overload of the transient type that matches the parameter types inferred from expression-1, expression-2, ... expression-n or by setting the specified properties property-1, property-2, ... property-n of the transient type. 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.
property-1, property-2, ... property-n
Properties of the specified transient type which are initialised with the given expressions (expression-1, expression-2, ... expression-n).
The properties can have any kind of accessibility, however for future compatibility with LINQ, we recommend to only use public properties. In order to initialise private data of a type, it is recommended that you use the constructor call syntax.
set
An OQL expression returning a Set<T> of scalars or persistent objects.

Remarks

This construct is used to retrieve a set of transient objects from the database. The expressions specified in the initializer can be scalar, persistent or nested array expressions.

The element type of the set projected with this construct is of the specified transient type 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.

This projection operation supports two alternative syntax flavours:
The first one attempts to match the return types inferred from the expressions to a corresponding constructor overload of the specified transient type.

The second one allows arbitrary public properties of the specified transient type to be initialised with the given expressions.

Quick Reference

OQL
[new AnimalInfo(Name, Cage.Name)]extentof(Zoo.Animal)


[new AnimalInfo{AnimalName=Name, CageName=Cage.Name}]extentof(Zoo.Animal)

C#
Set<AnimalInfo> animalInfos = myDB.Extent<Animal>().
Select<AnimalInfo>("new AnimalInfo(Name, Cage.Name)");



Set<AnimalInfo> animalInfos = myDB.Extent<Animal>().
Select<AnimalInfo>("new AnimalInfo{AnimalName=Name, CageName=Cage.Name}");

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

Examples

          
public class ExtendedEmployee
{
    public Employee PersistentData;
    public int NumberOfReports;
       
    public ExtendedEmployee(Employee persistentData, int numberOfReports)
    {
        PersistentData = persistentData;
        NumberOfReports = numberOfReports;
    }
}
                             
                             
                             
Set<ExtendedEmployee> employeeInfos = dd.Extent<Employee>().Select<ExtendedEmployee>("new ExtendedEmployee( this, Reports.Count )");
foreach (ExtendedEmployee e in employeeInfos) 
{
    Console.WriteLine("{0} {1}: {2} reports", e.FirstName, e.LastName, e.NumberOfReports);
}
        

See Also

Projection | OqlReference.Chapter5