---
title: "Walkthrough: Migrating a custom facet with complex types"
slug: "walkthrough--migrating-a-custom-facet-with-complex-types"
abstract: "Example of how to migrate complex data types into xConnect facets."
---
# Walkthrough: Migrating a custom facet with complex types

This walkthrough uses the [xDB Data Migration tool](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/xdb-data-migration-tool.html "xDB Data Migration Tool") but is applicable to any tool that migrates complex data types into xConnect facets.

> [!note]
> To migrate complex and custom types, you must register a custom migration model. For an example of how to do this, see [Implement components to store migrated data](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/implement-components-to-store-migrated-data.html "Implement components to store migrated data").

This walkthrough covers how to:

- [create a model in xConnect](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-b144becb-fcd3-48a7-b032-dd0b61924787_N1611322094977)
- [implement the Data Exchange Framework](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-b144becb-fcd3-48a7-b032-dd0b61924787_section-idm232226442484641 "Configure a custom facet in the Data Exchange Framework")

For the purpose of this walkthrough, it is assumed that you have a custom facet in a previous version of Sitecore that you implemented using, for example, code like this:

```csharp
public AvailablePublishersFacet : IFacet
    {
        IElementCollection<IAvailablePublishersElement> AvailablePublishers { get; }
        DateTime Updated { get; set; }
    }

public AvailablePublishersElement : IElement, IValidatable
    {
        string PublisherID { get; set; }
        int PublishStatus { get; set; }
    }
```

The contact, for example, uses the following code:

```csharp
{
  "_id": { "$binary": "Jj8PNya4NEy988az+LwtNA==", "$type": "3" },
  "AvailablePublishers": {
    "AvailablePublishers": {
      "0": { "PublisherID": "publisher1", "PublishStatus": 1 },
      "1": { "PublisherID": "ps2",
             "PublishStatus": 1 },
      "2": { "PublisherID": "ps3",
             "PublishStatus": 1 }
    },
    "LastUpdated": { "$date": "2020-02-23T06:`41:00`.572Z" }
  },
  "Lease": null,
  "System": { "VisitCount": 2 }
}
```

<details>
<summary><h2>Create a model in xConnect</h2></summary>

To create a model in xConnect:

- [Create a model](https://doc.sitecore.com/xp/en/developers/100/sitecore-experience-platform/create-a-custom-model.html) using, for example, the following code:

```csharp
using System;
using System.Collections.Generic;
using Sitecore.DataExchange.Tools.XdbDataMigration.Models;
using Sitecore.XConnect;
using Sitecore.XConnect.Schema;

namespace
{
    public class CollectionModel
    {
        public static XdbModel Model { get; } = CollectionModel.BuildModel();

        private static XdbModel BuildModel()
        {
var modelVersion = new XdbModelVersion(1, 0);
var builder = new XdbModelBuilder("Documentation.Model.CollectionModel", modelVersion);
builder.ReferenceModel(DataMigrationCollectionModel.Model);
builder.DefineFacet<Contact, AvailablePublishersFacet>(AvailablePublishersFacet.DefaultFacetKey);
return builder.BuildModel();
        }
    }

    [Serializable]
    public class AvailablePublishersFacet : Facet
    {
        public DateTime LastUpdated { get; set; }
        public const string DefaultFacetKey = "AvailablePublishers";
        public AvailablePublishersFacet()
        {
        }

        public Dictionary<string, AvailablePublisher> AvailablePublishers { get; set; } =
           new Dictionary<string, AvailablePublisher>();
    }

    [Serializable]
    public class AvailablePublisher
    {
        public AvailablePublisher(int publisherstatus, string publisherid)
        {
            this.PublisherID = publisherid;
            this.PublishStatus = publisherstatus;
        }
        public string PublisherID { get; set; }
        public int PublishStatus { get; set; }
    }
}
```

</details>

<details>
<summary><h2>Configure a custom facet in the Data Exchange Framework</h2></summary>

You can configure custom facets in Data Exchange Framework for different data providers. The following example shows you how to configure a custom facet for a MongoDB provider.

To configure a custom facet:

1. Compile the model into a DLL using Visual Studio, add it to the `bin` directory of the website, and restart Sitecore.
2. In the Content Editor, go to `/sitecore/System/Settings/Data Exchange/Providers/xConnect/Collection Models`, and create a new model. You can also update an existing one with the model you just created and deployed.

    ![Collection Model Type field for the collection model.](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/CollectionModelType.png)

3. On the ribbon menu, on the **Data Exchange** tab, click **Convert Model to JSON** to generate a JSON implementation. [Deploy the new model](https://doc.sitecore.com/xp/en/developers/100/sitecore-experience-platform/deploy-a-custom-model.html) to xConnect and the Indexing Service.
4. Create simple value accessor sets for the `mongodb` and `xConnect AvailablePublisher Entry` models using the [MongoDB Document Field Value Accessor](https://doc.sitecore.com/xp/en/developers/def/50/data-exchange-framework/en/document-field-value-accessor.html) and [xConnect XObject Property Value Accessor](https://doc.sitecore.com/xp/en/developers/def/50/data-exchange-framework/en/xobject-property-value-accessor.html).

    ![MongoDB Document Field Value Accessor](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/PublishStatus.png)

    ![xConnect XObject Property Value Accessor](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/PublishID.png)

    These value accessor sets are used for one-to-one mapping of each `AvailablePublisher` entity.

5. In the content tree, go to `/sitecore/System/Data Exchange/<tenant>/Value Mapping Sets/MongoDB`. Use the value accessors you created to create a one-to-one mapping for the `MongoDB collection` entry to the `xConnect Facet Dictionary` entry.

    ![Target Accessor for the PublisherID](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/TargetAccessor.png)

6. Add the `AvailablePublishers` value accessor for a source contact.

    ![AvailablePublishers Field section](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/AvailablePublisher.png)

You can now configure the mappings for the custom facet:

1. Go to `/sitecore/System/Data Exchange/<tenant>/Data Access/Value Readers/Providers/MongoDB` and create Dictionary Entries from the document value reader for `AvailablePublishers`.

    ![Dictionary Field Name for AvailablePublishers](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/AvailablePublisher2.png)

2. Go to /`Data Access/Value Accessor Sets/Providers/MongoDB/Create a Value Accessor Set`, select the general `Value Accessor` and assign the value reader you created to this accessor.

    ![Value Reader field for the Value Accessor](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/ValueReader.png)

3. On the `xConnect Provider`, use the `xConnect Entity Facet Value Accessor` and `xConnect Entity Facet Dictionary Property Value Accessor` templates to create an accessor for the `AvailablePublishers` facet and an accessor for the `AvailablePublishers Dictionary` facet property.

    ![One-to-one mapping](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/Mapping.png)

    > [!note]
    > Use the one-to-one mapping set created in [Step 5](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-b144becb-fcd3-48a7-b032-dd0b61924787_N1611924506399 "Step 5") as Dictionary Property Value Accessor.

4. Create a mapping set between the value accessor you created in [Step 1](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-b144becb-fcd3-48a7-b032-dd0b61924787_N1611328422720 "Step 1") and the `Facet AvailablePublishers Dictionary` property value accessor created in [Step 2](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-b144becb-fcd3-48a7-b032-dd0b61924787_N1611328461962 "Step 2").
5. Assign the mapping set you just created to the accessor for the `AvailablePublishers` facet.

    ![Target Accessor field for the Publishers](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/TargetAccessor2.png)

6. Add a mapping between MongoDB `AvailablePublishers` created in [Step 6](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-b144becb-fcd3-48a7-b032-dd0b61924787_N1611329694186 "Step 6") and the `xConnect AvailablePublishers` created in [Step 3](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-b144becb-fcd3-48a7-b032-dd0b61924787_N1611329680148 "Step 3").

    ![Mapping between the MongoDB Available Publishers and the xConnect AvailablePublishers.](https://doc.sitecore.com/api/markdown-image/xp/en/developers/dmt/50/xdb-data-migration-tool/images/MapBetweenMongoDBandxConnect.png)

> [!note]
> For information on how to map contact data in MongoDB to an xConnect contact facet in the XDB Data Migration tool, see [Map data from MongoDB to contact facet](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/map-data-from-mongodb-to-contact-facet.html "Map data from MongoDB to contact facet").

</details>