🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
InitialValue
This page was created by Lars.olofsson on 2024-01-16. Last edited by Wikiadmin on 2026-07-29.

You use Initial value on a modelled attribute to give each new in-memory object a starting value; this is for MDriven Designer users defining attribute behavior.

What Initial value does

Initial value is the value assigned when a new object is created in memory. It affects the new object before it is stored in the database.

For example, if an attribute named IsActive is a non-nullable Boolean and its Initial value is true, a newly created object starts with IsActive = true.

Set Initial value to a value appropriate for the attribute type. For a nullable attribute, you can leave it empty to start the attribute with no value.

Attribute type Example Initial value New object's in-memory value
Non-nullable Boolean true true
Non-nullable Decimal 0 0
String New customer New customer
Nullable attribute Leave empty No value (null)

Strings use the text itself, without database-style quotes. For example, enter New customer, not 'New customer'.

Set an Initial value

  1. Select the class attribute in MDriven Designer.
  2. In the attribute's property inspector, locate Initial value.
  3. Enter a value that matches the attribute type, or leave the property empty when the attribute is allowed to be null and should start without a value.
  4. Create a new object and verify that the attribute begins with the configured value.

Initial value is not DefaultDbValue

Initial value and DefaultDbValue serve different stages of the object's life:

Property Used when Value format
Initial value A new object is created in memory The model attribute's value format; for example true, 0, or New customer
DefaultDbValue The database is created or evolved The database engine's expected format; for example, SQL Server string values are quoted

Do not use Initial value as a replacement for DefaultDbValue. In particular, when you add a non-nullable attribute to an existing database, the database needs a value for existing rows. Most database engines require a DefaultDbValue for that evolve operation. See Documentation:Initial values and Default Database values for the database-evolve rules and SQL Server examples.

Initial value and Allow Null

Allow Null controls whether an attribute can hold no value, both in memory and in the database.

  • When Allow Null is enabled, you can leave Initial value empty when a new object should begin without a value.
  • When Allow Null is disabled, choose an Initial value that is valid for the attribute type. For example, use false or true for a Boolean, and 0 for a Decimal.
  • Initial value controls new in-memory objects. Database evolution requirements for non-nullable attributes are controlled separately through DefaultDbValue.

Example: an order status

Suppose an Order class has a String attribute named Status.

  1. Set its Initial value to New.
  2. Create an Order object in memory.
  3. The new object has Status = New until your application changes it.

If the attribute must also be added as non-nullable to a database that already contains Order rows, configure its database default according to Documentation:Initial values and Default Database values.

See also

[[Category:Attributes and data types [Beginner]]