HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Object configuration

Describes options for configuring business foundation objects.

These provide a lightweight object relational mapping (ORM) where you can add custom fields based on your business requirements. The Customer subsystem uses business foundation objects for their storage mechanism.

Classes in this topic are in the following namespaces:

  • Mediachase.BusinessFoundation.Data
  • Mediachase.BusinessFoundation.Data.Meta.Management
  • Mediachase.BusinessFoundation.Data.Modules

📘

Note

You should not modify the default business objects unless you have a full understanding of how it works.

Work with meta-class objects

Create objects

DataContext.Current = new DataContext(ServiceLocator.Current.GetInstance<IConnectionStringHandler>().Commerce.ConnectionString);
    ModuleManager.InitializeActiveModules();
    using (var scope = DataContext.Current.MetaModel.BeginEdit(MetaClassManagerEditScope.SystemOwner, AccessLevel.System))
    {
        var manager = DataContext.Current.MetaModel;
        var changeTrackingManifest = ChangeTrackingManager.CreateModuleManifest();
        var recentReferenceManifest = RecentReferenceManager.CreateModuleManifest();
        var budgetClass = manager.CreateMetaClass("Budget", "Budget", "Budgets", "cls_Budget", PrimaryKeyIdValueType.Integer);
        ModuleManager.Activate(budgetClass, changeTrackingManifest);
        using (var builder = new MetaFieldBuilder(budgetClass))
        {
            builder.CreateDateTime("StartDate", "StartDate", true, false);
            builder.CreateDateTime("EndDate", "EndDate", true, false);
            builder.CreateCurrency("Amount", "Amount", true, 0, true);
            builder.CreateText("Currency", "Currency", true, 50, false);
            builder.CreateText("Status", "Status", true, 50, false);
            builder.CreateCurrency("SpentBudget", "SpentBudget", true, 0, true);
            builder.CreateText("PurchaserName", "PurchaserName", true, 50, false);
            builder.CreateCurrency("LockOrganizationAmount", "LockOrganizationAmount", true, 0, true);
            var contactReference = builder.CreateReference("Contact", "CreditCard_mf_Contact", true, "Contact", false);
            var orgReference = builder.CreateReference("Organization", "CreditCard_mf_Organization", true, "Organization", false);
            builder.SaveChanges();
        }
    
        budgetClass.AddPermissions();
        scope.SaveChanges();
    }

Edit objects

DataContext.Current = new DataContext(ServiceLocator.Current.GetInstance<IConnectionStringHandler>().Commerce.ConnectionString);
    ModuleManager.InitializeActiveModules();
    using (var scope = DataContext.Current.MetaModel.BeginEdit(MetaClassManagerEditScope.SystemOwner, AccessLevel.System))
    {
        var manager = DataContext.Current.MetaModel;
        var contactMetaClass = manager.MetaClasses[ContactEntity.ClassName];
        var changeTrackingManifest = ChangeTrackingManager.CreateModuleManifest();
        var recentReferenceManifest = RecentReferenceManager.CreateModuleManifest();
        using (var builder = new MetaFieldBuilder(contactMetaClass))
        {
            builder.CreateText("UserRole", "{Customer:UserRole}", true, 50, false);
            builder.CreateText("UserLocation", "{Customer:UserLocation}", true, 50, false);
            builder.CreateInteger("Points", "{Customer:Points}", true, 0);
            builder.CreateInteger("NumberOfOrders", "{Customer:NumberOfOrders}", true, 0);
            builder.CreateInteger("NumberOfReviews", "{Customer:NumberOfReviews}", true, 0);
            builder.CreateText("Tier", "{Customer:Tier}", true, 100, false);
            builder.CreateText("ElevatedRole", "{Customer:ElevatedRole}", true, 100, false);
            builder.CreateHtml("Bookmarks", "{Customer:Bookmarks}", true);
            builder.SaveChanges();
        }
        contactMetaClass.DeleteMetaField("MiddleName");
        scope.SaveChanges();
    }

Delete objects

DataContext.Current = new DataContext(ServiceLocator.Current.GetInstance<IConnectionStringHandler>().Commerce.ConnectionString);
    ModuleManager.InitializeActiveModules();
    using (var scope = DataContext.Current.MetaModel.BeginEdit(MetaClassManagerEditScope.SystemOwner, AccessLevel.System))
    {
        var manager = DataContext.Current.MetaModel;
        manager.DeleteMetaClass("CreditCard");
        scope.SaveChanges();
    }