Home > Developing Using CodeFluent Entities > Property Default Values and Enumerations

Property Default Values and Enumerations

CodeFluent Entities defines the concept of “default value” for properties of any type, including value types and enums.

Each property has two types of default values:

  • the default value in the Persistence layer
  • the default value in the Business Object Model layer.
    In this article will focus on the default value in the Persistence Layer that allows to store undefined/null value types and enums (which cannot be nullable), in the database. So, for example, you can store null value types and enums without having to use .NET Nullable<T> type.

The default value depends on the type and what you should know is that for an enumeration type, the default value is the enumeration default value. By default, an enumeration default value is the first value. So for instance in the following example, “Valid” would be the default value and hence becoming NULL in database.

<cf:enumeration name=”EmailStatus” namespace=”Contacts”>
<cf:enumerationValue name=”Valid” /> <!– will become NULL in the Database –>
<cf:enumerationValue name=”Invalid” />

Obviously in the example above, considering the “Valid” enumeration value as the default value is not necessarily useful. Using an “Undefined” enumeration value for instance would be cleverer:

<cf:enumeration name=”EmailStatus” namespace=”Contacts”>
<cf:enumerationValue name=”Undefined” /> <!– will become NULL in the Database–>
<cf:enumerationValue name=”Valid” />
<cf:enumerationValue name=”Invalid” />

This is especially useful if it has some correspondence in the .NET code, for example, if you want to display a drop down list with a “not selected” option, or if you do conversion into this enum type and want to handle the “error” case.


Although the default values behavior is enabled by default you can also change it:

  • at the Property level by setting its “usePersistenceDefaultValue” attribute to false.

<cf:property name=”CollectionStatus” typeName=”Contacts.EmailStatus” usePersistenceDefaultValue=”false” />

  • at the Enumeration level by setting its “usePersistenceDefaultValue” attribute to false.

<cf:enumeration name=”Contacts.EmailStatus” namespace=”Contacts” usePersistenceDefaultValue=”false” />

  • at the Project level by setting its “defaultUsePersistenceDefaultValue” attribute to false.

<cf:project […] defaultUsePersistenceDefaultValue=”false” />


More on Default Values in the documentation: Property Default Values



Thibault NESTOR

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s