DevForce Help Reference
DefaultValueFunction Property
Example 


Use to override how DevForce sets the default value for a data entity property.
Syntax
'Declaration
 
Public Shared Property DefaultValueFunction As Func(Of Type,Object)
'Usage
 
Dim value As Func(Of Type,Object)
 
EntityMetadata.DefaultValueFunction = value
 
value = EntityMetadata.DefaultValueFunction
public static Func<Type,object> DefaultValueFunction {get; set;}
Remarks
Use the DefaultValueFunction to override how DevForce determines the default value for a DataEntityProperty. If you do not specify an override, the value returned by DevForceDefaultValueFunction is used. Note that the override is not on an Entity basis - the override will apply to all Entity types. For example, you may want to override the default DateTime value with your own code - this override would apply to DateTime data entity properties in all Entity types.

You must set your override for the DefaultValueFunction as early as possible in your processing. The DataEntityProperties of your entities are static fields of these entities, and will be initialized as the entity types are referenced.

Example
// To override the default value used for some property types.
// Here, DateTime properties default to Today with an Unspecified Kind, and
// longs to -1; all other types will use the DevForce-provided default value.

EntityMetadata.DefaultValueFunction = (t) => {
  if (t == typeof(DateTime)) { return DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Unspecified); }
  if (t == typeof(long)) { return -1L; }
  return EntityMetadata.DevForceDefaultValueFunction(t);
};
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityMetadata Class
EntityMetadata Members

Send Feedback