Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide
GitHubNuGetDev CommunityOptimizely AcademySubmit a ticket

Optimizely developer documentation

How can we help you?

Try our conversational search powered by Generative AI!

AI OnAI Off

Export and import meta-models

Describes how to export and import meta-models in Business Foundation (BF).

You can export and import meta-models. You also can compare two meta-models, which is useful during these operations.

The following classes are available in the Mediachase.BusinessFoundation.Data.Meta.Schema namespace.

Export meta-models

Export a meta-model to a file with the MetaModelGenerator class. By default, MetaModelGenerator exports all elements; use the SelectedElements property of the MetaModelGenerator class to export custom elements.

Example: Exporting a meta-model to a file

// Create MetaModelGenerator MetaModelGenerator generator = new MetaModelGenerator(); // Use generator.SelectedElements to export custom elements try { // Open DataContext DataContext.Current = new DataContext(connectionString); // Load Save Commands SchemaDocument schema = new SchemaDocument(); schema.LoadDefault(); generator.Schema = schema; // Load Save Commands XmlDocument xmlOutput = generator.Generate(); xmlOutput.Save(filePath); } catch (Exception ex) { }

Compare meta-models

Before you import a meta-model, you should compare meta-models and create synchronization commands. You can export and compare an existing meta-model with the one you are about to import before importing it.

Example: Compare two meta-models and create synchronization script

try { // Load Imported Meta-Model List<ModuleManifest> installedModules = new List<ModuleManifest>(); XmlDocument xmlSrcMetaModel = new XmlDocument(); xmlSrcMetaModel.Load(srcMetaModelPath); // Load Modules From Source Meta-Model foreach (XmlNode xmlManifestNode in xmlSrcMetaModel.SelectNode("//mediachase.businessFoundation.data.meta/description/moduleManifests/moduleManifest")) { ModuleManifest manifest = McXmlSerializer.GetObject<ModuleManifest>(xmlManifestNode.OuterXml); installedModules.Add(manifest); } // Load SchemaDocument SchemaDocument schema = new SchemaDocument(); schema.LoadDefault(installedModules.ToArray()); // Load Original Meta-model XmlDocument xmlDestMetaModel = new XmlDocument(); xmlDestMetaModel.Load(destMetaModelPath); // Compare two Meta-models SyncCommand\[] syncCommands = MetaModelSync.FindModifications(schema, xmlSrcMetaModel, xmlDestMetaModel); // Save sync commands to file McXmlSerializer.SaveObjectToFile<SyncCommand\[\]>(outputSyncFilePath, syncCommands); } catch (Exception ex) { }

Import meta-models

When importing a meta-model, follow these steps.

  1. Export the original meta-model.
  2. Compare it with the meta-model to be imported.
  3. Create synchronization commands (described in the previous section).
  4. Execute the synchronization commands.

Example: Loading and executing synchronization commands

try { // Open DataContext DataContext.Current = new DataContext(connectionString); // Load Sync Commands SchemaDocument schema = new SchemaDocument(); schema.LoadDefault(); // Load Sync Commands SyncCommand\[] syncCommands = McXmlSerializer.GetObjectFromFile<SyncCommand\[]>(filePath); // Apply Sync Command using (TransactionScope tran = DataContext.Current.BeginTransaction()) { MetaModelSync.Execute(schema, syncCommands); tran.Commit(); } } catch (Exception ex) { }

Did this page help you?