Loading...
Area: Episerver Commerce
Applies to versions: 10
Other versions:

MetaClassManager class

The MetaClassManager class represents the entry point to the meta-model and is available from the DataContext.MetaModel property. Use the MetaModel to get meta-classes, registered meta-types and relationships, and to create and delete meta-classes. Also, MetaClassManager includes the static events MetaClassCreating, MetaClassCreated, MetaClassDeleting, MetaClassDeleted, MetaFieldCreating, MetaFieldCreated, MetaFieldDeleting, MetaFieldDeleted. You can subscribe to these events 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.

Runtime mode is a default state allowing for working with objects. You can create, load, update, and delete entity objects in this mode.

You can modify a meta-model only in Design mode, so if you want to change the meta-model, activate Design mode. 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 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 initializing the MetaClassManagerEditScope object and calling its Dispose method), the transaction in which the scope participates is allowed to proceed. If an exception occurs within the edit scope, the transaction in which it participates is rolled back.

When your application completes work needed in a transaction, call the SaveChanges method only once to inform that meta-model manager that it can 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

// Open Meta-model edit scope
using (MetaClassManagerEditScope scope =
DataContext.Current.MetaModel.BeginEdit())
{
// Modify meta-model here
// Save Changes
scope.SaveChanges();
}
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 24, 2016