TechTalk Genome v4.2

<Index> Element

Note: This documentation is preliminary and is subject to change.

Defines an index on a type, providing direct access to objects based on the values of certain selected fields.

<Member name=" property "
Index=" index "
/>

or

<Member name=" property ">
<Index [name="index"] [maxFill="max-number-of-objects"] />
</Member>

or

<Type name=" type ">
<Index [name="index"] [maxFill="max-number-of-objects"] >
(<Member>property</Member>)+
</Index>
</Type>
type
A type specifying a persistent class.
property
A persistent property that is mapped using one of the field mappings.
index
A name identifying the index within the type. If the index is not specified, the name of the property is used.
max-number-of-objects
A positive number or the Infinite term, specifying the maximum number of objects with the same index value. If the max-number-of-objects is not specified, the number of objects is unlimited.

Remarks

<Index> element defines the index on the type, providing direct access to objects based on the values of the selected propertys. The max-number-of-objects can be used to specify the maximum number of presistent objects with the same index value. Setting the max-number-of-objects as 1 declares the index to be a unique index.

Genome can use indexes to improve performance of queries that use indexed properties in their filter criteria.

Examples

          
Employee.cs
                    
public abstract class Employee : Persistent {
    ...
    
    public abstract Car Car { get; set; }
}   

public abstract class Car {
    ...
    
    public abstract Employee AssignedTo { get; }
    
        return (Employee)DataDomain.Select(
            "extentof(Northwind.Business.Employee)[e: e.Car == this].ToObject() " +
            "with(IndexUsage="Car", Index_Car=[{0}])", 
            this).ToObject(); 
    }
}
                    
                    
          
Northwind.xml
                        
<Mapping xmlns="urn:TechTalk:TT.OODAL.XmlMapping">
    ...

    <Type name="Employee">

        <!-- indexes the FirstName property of the Employee -->
        <Member name="FirstName" PersistentField="FN" Index="IdxFirstName" />
        
        <!-- creates a unique index to the Car property to make the back-reference
             on the Employee-Car one-one relation faster -->
        <Member name="Car">
            <NearObjectReference />
            <Index name="IdxCar" maxFill="1" />
        </Member>
        
    </Type>
    
    <Type name="Car">
        
        <Member name="AssignedTo"
            Oql='extentof(Employee)[e: e.Car == this].ToObject()
                    with(IndexUsage="IdxCar", Index_Car=[this])' />
    </Type>
    
</Mapping>
                    
                        
// this function searches for the employee having a specified car                   
public static Employee GetEmployeeByCar(Car car) {

    return (Employee)DataDomain.Select(
        "extentof(Northwind.Business.Employee)[e: e.Car == {0}].ToObject() " +
            "with(IndexUsage="IdxCar", Index_Car=[{0}])", 
        this).ToObject(); 
}

// returns the set of employees having the specified first name
public static Set GetEmployeesByFirstName(string fistName) {

    return DataDomain.Select(
        "extentof(Northwind.Business.Employee)[e: e.FirstName == {0}].ToObject() " +
            "with(IndexUsage="IdxFirstName", Index_FirstName=[{0}])", 
        firstName); 
}
                                    
                    

Requirements

Type: TechTalk.Genome.Mapping.IndexXmlData

Assembly: TechTalk.Genome.dll

Version: 4.2.4

Editions: Professional, Evaluation, Express

Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2

See Also

Usage of Indices | Other Elements