---
title: "攻略:複雑なタイプのカスタムファセットの移行"
slug: "walkthrough--migrating-a-custom-facet-with-complex-types"
abstract: "複雑なデータ型をxConnectのファセットに移行する方法の例です。"
---
# 攻略:複雑なタイプのカスタムファセットの移行

このウォークスルーは[xDBデータ移行ツール](https://doc.sitecore.com/xp/en/developers/dmt/50/xdb-data-migration-tool/xdb-data-migration-tool.html) を使用していますが、複雑なデータ型をxConnectの面に移行するすべてのツールに適用可能です。

> !注複雑型やカスタム型を移行するには、カスタムマイグレーションモデルを登録する必要があります。その方法の例は「 [移行データを格納するコンポーネントの実装](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/implement-components-to-store-migrated-data.html "Implement components to store migrated data")」を参照してください。

このウォークスルーでは、以下の方法を説明します:

-   [xConnectでモデルを作成する](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-fe72e103-13d8-2903-1444-1217922814a6_N1611322094977)
-   [データ交換フレームワークの実施](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-fe72e103-13d8-2903-1444-1217922814a6_section-idm232226442484641 "Configure a custom facet in the Data Exchange Framework")

このウォークスルーの目的上、あなたが以前のSitecoreのバージョンにカスタムファセットを実装し、例えば次のようなコードを使って実装したことを前提としています:

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

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

例えば、その連絡先は以下のコードを使います。

{
 "\_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 }
}

## xConnectでモデルを作成する

xConnectでモデルを作成するには:

-   [例えば、以下のコードを使ってモデルを作成します。](https://doc.sitecore.com/xp/en/developers/90/sitecore-experience-platform/en/create-a-custom-model.html)

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; }
 }
}

## Data Exchange Frameworkでカスタムファセットを設定する

Data Exchange Frameworkでは、異なるデータプロバイダー向けにカスタムファセットを設定できます。以下の例では、MongoDBプロバイダーのカスタムファセットの設定方法を示しています。

カスタムファセットの設定:

1.  Visual Studioを使ってモデルをDLLにまとめ、ウェブサイトのbinディレクトリに追加し、Sitecoreを再起動します。
    
2.  コンテンツエディターで /sitecore/System/Settings/Data Exchange/Providers/xConnect/Collection Modelsに移動し、新しいモデルを作成します。また、作成したばかりのモデルで既存のモデルを更新することもできます。
    
    ![Collection Model Type field for the collection model.](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/CollectionModelType.png)
    
3.  リボンメニューの**Data Exchange**タブで「 **モデルをJSONに変換** 」をクリックしてJSON実装を生成します。 [新しいモデルを](https://doc.sitecore.com/xp/en/developers/90/sitecore-experience-platform/en/deploy-a-custom-model.html)xConnectとインデックスサービスに展開します。
    
4.  mongodbモデルとxConnect AvailablePublisher Entryモデル用の簡単な値アクセスセットを作成し、[MongoDB Document Field Value Accessor](https://doc.sitecore.com/xp/en/developers/def/20/data-exchange-framework/en/document-field-value-accessor.html)と[xConnect XObjectプロパティValue Accessor](https://doc.sitecore.com/xp/en/developers/def/20/data-exchange-framework/en/xobject-property-value-accessor.html)を使用します。
    
    ![MongoDB Document Field Value Accessor](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/PublishStatus.png)
    
    ![xConnect XObject Property Value Accessor](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/PublishID.png)
    
    これらの値アクセスセットは、各AvailablePublisherエンティティの1対1のマッピングに使用されます。
    
5.  コンテンツツリーで /sitecore/System/Data Exchange/<tenant>/Value Mapping Sets/MongoDBに移動します。作成した値のアクセサを使って、MongoDB collectionエントリからxConnect Facet Dictionaryエントリへの1対1のマッピングを作成します。
    
    ![Target Accessor for the PublisherID](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/TargetAccessor.png)
    
6.  ソースコンタクトのAvailablePublishers値インセクターを追加します。
    
    ![AvailablePublishers Field section](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/AvailablePublisher.png)
    

カスタムファセットのマッピングを設定できます:

1.  ドキュメントバリューリーダーから辞書エントリーを作成/sitecore/System/Data Exchange/<tenant>/Data Access/Value Readers/Providers/MongoDBAvailablePublishers。
    
    ![Dictionary Field Name for AvailablePublishers](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/AvailablePublisher2.png)
    
2.  /Data Access/Value Accessor Sets/Providers/MongoDB/Create a Value Accessor Setに移動し、一般的なValue Accessorを選択し、作成した値リーダーをこのアクセルに割り当てます。
    
    ![Value Reader field for the Value Accessor](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/ValueReader.png)
    
3.  xConnect Providerでは、xConnect Entity Facet Value AccessorとxConnect Entity Facet Dictionary Property Value Accessorテンプレートを使って、AvailablePublishers面のアクセルとAvailablePublishers Dictionary面プロパティのアクセルを作成します。
    
    ![One-to-one mapping](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/Mapping.png)
    
    > !注 [ステップ5](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-fe72e103-13d8-2903-1444-1217922814a6_N1611924506399 "Step 5")で作成された1対1のマッピングセットを辞書プロパティ値のアクセサとして使用してください。
    
4.  [ステップ1](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-fe72e103-13d8-2903-1444-1217922814a6_N1611328422720 "Step 1")で作成した値のアクセルと[、ステップ2](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-fe72e103-13d8-2903-1444-1217922814a6_N1611328461962 "Step 2")で作成したFacet AvailablePublishers Dictionaryプロパティのバリューアクセルの間にマッピングセットを作成します。
    
5.  作成したマッピングセットを、AvailablePublishers面のアクセルに割り当てます。
    
    ![Target Accessor field for the Publishers](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/TargetAccessor2.png)
    
6.  [ステップ6](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-fe72e103-13d8-2903-1444-1217922814a6_N1611329694186 "Step 6")で作成されたMongoDB AvailablePublishersと[ステップ3](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/walkthrough--migrating-a-custom-facet-with-complex-types.html#UUID-fe72e103-13d8-2903-1444-1217922814a6_N1611329680148 "Step 3")で作成されたxConnect AvailablePublishersの間にマッピングを追加します。
    
    ![Mapping between the MongoDB Available Publishers and the xConnect AvailablePublishers.](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/dmt/50/xdb-data-migration-tool/images/MapBetweenMongoDBandxConnect.png)
    

> !注MongoDBの連絡先データをXDBデータ移行ツールのxConnectの連絡先ファセットにマッピングする方法については、「 [MongoDBから連絡先へのMapデータ](https://doc.sitecore.com/xp/ja/developers/dmt/50/xdb-data-migration-tool/map-data-from-mongodb-to-contact-facet.html "Map data from MongoDB to contact facet")」をご覧ください。