2

How are you guys handling multiple version of a marketingautomationengine model in your current solution.

Let's assume I have mymodel,1.0.json which looks like below

{
  "Name": "mymodel",
  "Version": "1.0",
  "References": [
    {
      "Name": "XConnect",
      "Version": "1.0"
    },
    {
      "Name": "Sitecore.XConnect.Collection.Model",
      "Version": "9.0"
    }
  ],
  "Types": {
    "My.Project.Namespace.Facets.Model1": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "My.Project.Namespace.Facets.Model1, My.Project.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "Id": {
          "Type": "String"
        },
        "Name": {
          "Type": "String"
        },
        "SomeProp": {
          "Type": "String"
        }
      }
    },
    "My.Project.Namespace.Facets.Model2": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "My.Project.Namespace.Facets.Model2, My.Project.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "SomeOtherId": {
          "Type": "String"
        },
        "CustomerName": {
          "Type": "String"
        },
        "PostalCode": {
          "Type": "String"
        }
      }
    },
    "My.Project.Namespace.Facets.Model3": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "My.Project.Namespace.Facets.Model3, My.Project.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "Lorem": {
          "Type": "String"
        }
      }
    }
  },
  "Facets": [
    {
      "Target": "Contact",
      "Name": "FacetName1",
      "Type": "My.Project.Namespace.Facets.Model1"
    },
    {
       "Target": "Contact",
      "Name": "FacetName2",
      "Type": "My.Project.Namespace.Facets.Model2"
    },
    {
       "Target": "Contact",
      "Name": "FacetName3",
      "Type": "My.Project.Namespace.Facets.Model3"
    }
  ]
}

And I want to modify this model definition by removing the FacetName2 definition, but instead of generating a MarketingAutomation model with the same version number, I would increase its version to 2.0 so it would look like this.

Model name would be mymodel,2.0.json

{
  "Name": "mymodel",
  "Version": "2.0",
  "References": [
    {
      "Name": "XConnect",
      "Version": "1.0"
    },
    {
      "Name": "Sitecore.XConnect.Collection.Model",
      "Version": "9.0"
    }
  ],
  "Types": {
    "My.Project.Namespace.Facets.Model1": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "My.Project.Namespace.Facets.Model1, My.Project.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "Id": {
          "Type": "String"
        },
        "Name": {
          "Type": "String"
        },
        "SomeProp": {
          "Type": "String"
        }
      }
    },
    "My.Project.Namespace.Facets.Model3": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "My.Project.Namespace.Facets.Model3, My.Project.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "Lorem": {
          "Type": "String"
        }
      }
    }
  },
  "Facets": [
    {
      "Target": "Contact",
      "Name": "FacetName1",
      "Type": "My.Project.Namespace.Facets.Model1"
    },

    {
       "Target": "Contact",
      "Name": "FacetName3",
      "Type": "My.Project.Namespace.Facets.Model3"
    }
  ]
}

At this point, mymodel,1.0.json and mymodel,2.0.json are both present in the folder \App_data\jobs\continuous\IndexWorker\App_data\Models and Xconnect\App_Data\Models

And I get

2020-04-22 12:15:20.712 +02:00 [Error] XConnect Web Application Error: "System.ApplicationException: Exception trying to initialize Service Collection and Provider for WebAPI Dependency Resolver, Inner Exception: Different models with the same names are referenced ('mymodel') ---> Sitecore.XConnect.Schema.DuplicateXdbModelNameException: Different models with the same names are referenced ('mymodel')
   at Sitecore.XConnect.Schema.XdbModel.AddAndValidateModelAndTypes(XdbModel model, HashSet`1 visited)
   at Sitecore.XConnect.Schema.XdbModel.AddAndValidateModelAndTypes(XdbModel model, HashSet`1 visited)
   at Sitecore.XConnect.Schema.XdbModel..ctor(String name, XdbModelVersion version, XdbNamedType[] types, XdbFacetDefinition[] facets, XdbModel[] referencedModels)
   at Sitecore.XConnect.Schema.XdbRuntimeModel..ctor(XdbModel[] models)
   at Sitecore.XConnect.Web.Extensions.UseXConnectModel(IServiceCollection services)
   at Sitecore.XConnect.DependencyInjection.ServiceCollectionExtensions.GetXConnectServiceConfiguration(IServiceCollection services)
   at Sitecore.XConnect.Web.WebApiConfig.ConfigureServices(HttpConfiguration config)
   --- End of inner exception stack trace ---
   at Sitecore.XConnect.Web.WebApiConfig.ConfigureServices(HttpConfiguration config)
   at System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback)
   at Sitecore.XConnect.Web.Global.Application_Start(Object sender, EventArgs e)"

How would you guys handle this kind of situation?

1

As far as I know the version of the model is purely semantic for humans. Probably more to quickly let us know what version is deployed.

Model names must be unique across all referenced models. -Source

So therefore, if you change your model, it could be good practice to up the version for others on your team to know it's changed, or to be sure what version is on specific environments. But you can't have more than 1 version of the model deployed at a time, so it doesn't really matter too much whether you change the version or not.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.