This content is archived. See latest version here

Last updated: Oct 21 2014

The MetaType class represents for instance the field type declarations string, HTML text, number, enums, file, and image. MetaType includes all common types and can also be extended with UI friendly types. For example, instead of using one type of string, BusinessMeta Model has Short String, Long String, HTML, Email, Phone and number. You can easily create a new MetaType based on system type or create acustom one.

Business Foundation(BF) is designed to enable you to easily use a number of different meta types for your .NET applications. You can use the included meta types, or you can implement your own custom meta type.

Default meta types

Call the RegisteredTypes method of MetaClassManager class to get all registered meta types. Business Foundation has a number of ready-to-use meta types listed below.

NameSystem TypeDescription

Guid

Guid

Represents a globally unique identifier (GUID).

DateTime

DateTime

Represents an instant in time, typically expressed as a date and time of day.

Date

DateTime

Represents an instant in date.

Integer

Integer

Represents a 32-bit signed integer.

Float

Double

Represents a double-precision floating-point number.

Currency

Currency

Represents a currency number .

CheckboxBoolean

Boolean

Represents a Boolean value with checkbox.

DropDownBoolean

Boolean

Represents a Boolean value with drop-down.

Text

String

Represents text with fixed length. Maximum length is 4096 chars.

EMail

String

Represents an e-mail string.

Url

String

Represents an URL string.

LongText

String

Represents a long text.

Html

String

Represents an HTML string.

File

File

Represents a file (name, length, content type, stream).

Image

File

Represents an image file.

IntegerPercent

Integer

Represents a 32-bit signed integer percent.

FloatPercent

Double

Represents a double-precision floating-point percent.

Duration

Integer

Represents a 32-bit signed integer duration value.

Creating a meta type based on system type

You can easily create a new meta type based on system type. You can find a complete list of system types in the McDataType enumerators.

To create a meta type, for example Geolocation based on the String system type, open the edit scope and add a new MetaFieldType object to the MetaClassManager.RegisteredTypes collection.

C#
// Open Meta model edit scope
using (MetaClassManagerEditScope scope =
DataContext.Current.MetaModel.BeginEdit())
{
// Add a new meta type
MetaFieldType geoLocation = new MetaFieldType("Geolocation",
"Geolocation", McDataType.String);
DataContext.Current.MetaModel.RegisteredTypes.Add(geoLocation);
// Save Changes
scope.SaveChanges();
}

Or, add a new record to the mcmd_MetaFieldType table and restart the application.

*INSERT INTO mcmd_MetaFieldType ([Name], [FriendlyName], [McDataType]) VALUES ('Geolocation', 'Geolocation ', 6

After registration, you can add a geolocation field to the meta class. Using the meta type name you can load a new gelolocation view, and edit the UI control.

Creating a custom meta type

When implementing a custom meta type, you need to create the Meta field installer and Meta field property binder. When you create a meta field, BF calls the meta field installer to process meta field into SQL columns. When you load an entity object, BF calls the meta object property binder to convert values from an SQL column to a meta field value.

To create a custom Meta field installer, you create a class that implements the IMetaFieldInstaller interface, and implement the AssignDataSource, AssignValidators, UpdateDataSource, UpdateValidators, RemoveDataSource, RemoveValidators methods.

NameDescription

AssignDataSource

Create a new columns in the SQL database from meta field

AssignValidators

Assign default validators

UpdateDataSource

Update SQL columns from updated meta field

UpdateValidators

Update validators

RemoveDataSource

Remove columns from SQL database

RemoveValidators

Remove validators

To create a custom Meta object property binder, you create a class that implements the IMetaObjectPropertyBinder interface, and implement the PostLoad, PostLoad, PreSave, PostSave, Delete, InitTableConfig methods.

NameDescription

PreLoad

Load value from SQL row and save to meta field property

PostLoad

Fill properties by other.

PreSave

Save value to SQL row

PostSave

Fill properties by other.

Delete

Clean up if meta field is removing

InitTableConfig

Initialize additional SQL relations

The custom meta field installer and meta object property binder should be registered in the mediachase.businessFoundation.data/metaObject/types section of the application config file.

XML
 <mediachase.businessFoundation.data>
<metaObject>
<types>
<add name="CustomType" installer="" binder="" />*
</types>

Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/