<PersistentField> Element

Stores a scalar persistent property in a database field.

<Member name="property">

       <PersistentField [fieldName="database-field-name"] [database-type-modifiers]>






<Member name="property" PersistentField="database-field-name"/>

property: The name of an abstract property of the persistent class, that returns a scalar type. The property can have a getter (read only), or setter (write only), or both (read and write).

database-field: An identifier specifying the name of the database field the property is mapped to. The name of property is used by default if database-field is omitted.

identity-strategy-element: An optional strategy modifier, specifying if this property is assigned by Genome when the object is created. If set, the property must be read only (can have only a getter). This modifier is currently supported only on fields that are part of the primary key of the type. For a list of identity strategies, see Object Identity Generation Strategies.

default-value-initialiser: Specifies a default value initialisation strategy for the mapped field. See <DefaultValue/> mapping element.

database-type-modifiers: An optional list of database type modifiers that can change the type of the database field. The default mapping for the type of the property is used if no modifier is specified. The defaults can be found in the description of Database Type Modifiers.


The <PersistentField> element stores the value of the property in the database-field in the table specified by the extent provider. The type of the database-field is determined by the type of the property and it can be altered by specifying database-type-modifiers.

In reference type properties (string, byte[], etc.), the database NULL value is represented by a null reference. Since properties of value types cannot have a null reference, database NULL values cannot be stored in such properties. When it is necessary to store NULL values in value type properties, the developer can use the System.Nullable<T> types or the database platform specific ADO.NET helper classes, e.g.: SqlDecimal.

A property mapped with PersistentField can be used in C# code and server-side query 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.


Mapping a persistent class with persistent fields

Persistent class Employee has three fields in the database:

public abstract class Employee : Persistent


    public abstract string FirstName { get; set; }

    public abstract DateTime BirthDate { get; set; }

    public abstract string HomePhone { get; set; }



<Type name="Employee">


    <!-- FirstName will be stored in the "FirstName nvarchar(255)" field -->

    <Member name="FirstName">

        <PersistentField />



    <!-- BirthDate will be stored in the "dtBirthDate datetime" field -->

    <Member name="BirthDate" PersistentField="dtBirthDate" />  


    <!-- HomePhone will be stored in the "strPhone varchar(24)" field -->

    <Member name="HomePhone">

        <PersistentField fieldName="strPhone" Length="24" Unicode="false" />




Editions:Professional, Evaluation, Express

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

See Also

Field Mappings | Database Type Modifiers | <NearObjectReference> Element | <Ignore> Element | Object Identity Generation Strategies | <DefaultValue> Element