This content is archived. See latest version here

Last updated: Oct 21 2014

The MetaClassManager class represents the entry point to the meta model. It is available from the DataContext.MetaModel property. The MetaModel is used for getting meta classes, registered meta types and relationships, as well as for creating and deleting meta classes. Also, MetaClassManager includes the static events MetaClassCreating, MetaClassCreated, MetaClassDeleting, MetaClassDeleted, MetaFieldCreating, MetaFieldCreated, MetaFieldDeleting, MetaFieldDeleted. You can subscribe to these events in order to get information about external meta model modifications.

MetaModel edit scope

The Business Meta Model can enter these modes:

  • Runtime - the default mode where users can work with data only.
  • Design - enables users to modify the meta model.

A runtime mode is a default state allowing for work with objects, and you can create, load, updated and delete entity objects in this mode.

A meta model can only be modifiedinDesign mode so if you want to change themeta model you should activate the Design mode. The Design Mode creates a local copy of the meta model and commits modifications only after final commit.

Upon instantiating a MetaClassManagerEditScope by the calling MetaClassManager.BeginEdit statement, the meta model manager determines which mode to participate in. Once determined, the scope always participates in that edit scope. You can obtain a reference to the ambient edit scope by calling the Current property of the MetaClassManagerEditScope class.

If no exception occurs within the transaction scope (that is, between the initialization of the MetaClassManagerEditScope object and the calling of its Dispose method), then the transaction in which the scope participates is allowed to proceed. If an exception does occur within the edit scope, the transaction in which it participates will be rolled back.

When your application completes all work needed in a transaction, you should call the SaveChanges method only once to inform that meta model manager that it is acceptable to commit the transaction. Failing to call this method aborts the transaction. Afterwards, the SaveChanges meta model modifications are available to all users. A call to the Dispose method marks the end of the edit scope. Exceptions that occur after calling this method may not affect the transaction.

Example: The Open meta model edit scope

C#
// Open Meta model edit scope
using (MetaClassManagerEditScope scope =
DataContext.Current.MetaModel.BeginEdit())
{
// Modify meta model here
// Save Changes
scope.SaveChanges();
}

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/