Defines a transient field that is not persisted in the database.
The <TransientField> element defines that the property is a field of the object, but it is not directly bound to a database field. Similarly to the <PersistentField> , the property accesses the object state in the Context associated with the object.
If no OqlInitializer is specified, the property can be of any arbitrary type as it does not have to be bound to the database. Of course, the property cannot be used in OQL expressions for the same reason. A transient field without an initialiser behaves like a C# field on a POCO; the value can be freely get and set, and getting an uninitialised transient field returns a null reference for reference types and the default value for value types.
If there is a specified OqlInitializer, the property must have a scalar return type. In this case, the transient field is populated with the value of the oql initializer expression when the object is loaded from the database. If the object is already in memory, the transient field can be freely get and set, and the initializer will be not executed again. If the transient field is not loaded yet (eg. new object or partially loaded object) an appropriate query is executed to populate the value of the transient field (lazy loading). By specifying the initializer, the property can be used in OQL expressions, just as if it were mapped with the <Oql> element .
Customer.cs
public abstract class Customer : Persistent {
...
public abstract decimal? OrderVolume { get; }
}
Customer.xml
<Type name="Customer">
<Member name="OrderVolume">
<TransientField OqlInitializer="Sql.Sum([Value]Orders)" />
</Member>
</Type>
Type: TechTalk.Genome.Mapping.TransientFieldXmlData
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