TechTalk Genome v4.2

<NearObjectReference> Element

Stores a reference to a persistent type in one or more database fields.

<Member name=" property ">
<NearObjectReference [fieldPrefix="field-prefix"] >
[check-integrity-directive]
</NearObjectReference>
</Member>

or

<Member name=" property "
NearObjectReference=" field-prefix "
/>

or

<Member name=" property ">
<NearObjectReference >
(<Map primaryKeyName="primary-key-field" foreignKeyName="foreaign-key-field" />)+
[check-integrity-directive]
</NearObjectReference>
</Member>
property
A property referring to a persistent type. The property can have getter or setter or both.
field-prefix
An identifier that is used to prefix the name of primary key fields of the type referred by property when naming the foreign key fields. The name of the property is used as prefix when the field-prefix is not specified.
primary-key-field
The name of a primary key field.
foreign-key-field
The name of a foreign key field that primary-key-field is mapped to.
check-integrity-directive
The <CheckIntegrity> element specifies if referential integrity is enforced with a foreign key constraint in the database.

Remarks

The <NearObjectReference> element can be used to store a property that refers to an object in the same DataDomain. NearObjectReference creates a foreign key field for every primary key field of the referred type.

The field-prefix can be used to name foreign keys by prefixing the foreign keys with field-prefix. The <Map> element can be used to achieve one-by-one naming for each primary key field. When using one-by-one naming, all primary key fields have to be mapped to a foreign key field. The type of the created database fields is inherited from the identity fields of the referred type.

If the property of an object refers to another object, then all foreign key fields have to contain an non- NULL value. If the property does not refer to any object, then all foreign key fields have to contain a database NULL value and the property contains a null reference.

A property mapped with PersistentField can be used in C# code and OQL expressions. The property is implemented by accessing the object state in the Context associated with the object.

When mapping to read-only databases, the setter of the property can be omitted.

Examples

          
Order.cs
                
public abstract class Shipper : Persistent {
    ...
    public abstract int Id { get; set; }
}

public abstract class Order : Persistent {
    ...
    public abstract Shipper ShipVia { get; set; }
}
                
          
NorthwindSchema.xml    
                
<Mapping xmlns="urn:TechTalk:TT.OODAL.XmlMapping">
    ...

    <Type name="Shipper">
        ...

        <PrimaryKey><Key>Id</Key></PrimaryKey>
        
        <Member name="Id" PersistentField="SNr" />
    </Type>
    
    <Type name="Order">
        ...
    
        <!-- the ShipVia reference will be stored in the "ShipViaSNr int" PK field -->
        <Member name="ShipVia">
            <NearObjectReference />
        </Member>
        
        - or -
        
        <!-- the ShipVia reference will be stored in the "ShipperSNr int" PK field -->
        <Member name="ShipVia" NearObjectReference="Shipper" />

        - or -

        <!-- the ShipVia reference will be stored in the "SHP int" PK field -->
        <Member name="ShipVia">
            <NearObjectReference>
                <Map primaryKeyName="SNr" foreignKeyName="SHP" />
            </NearObjectReference>
        </Member>

    </Type>
    
</Mapping>
                

Requirements

Type: TechTalk.Genome.Mapping.NearObjectReferenceXmlData

Assembly: TechTalk.Genome.dll

Version: 4.2.11

Editions: Professional, Evaluation, Express

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

See Also

Field Mappings | XmlMapping.Elements.PersistentField | <Ignore> Element | <CheckIntegrity> Element