Skip to main content
added 196 characters in body
Source Link
Foysal
  • 506
  • 2
  • 13
namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
}

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

        private static XdbModel BuildModel()
        {
            XdbModelBuilder modelBuilder = new XdbModelBuilder("XYZ.Model.DynamicDataModel", new XdbModelVersion(1, 0));
            modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            modelBuilder.DefineFacet<Contact, DynamicDataFacet>(DynamicDataFacet.DefaultFacetKey);
            return modelBuilder.BuildModel();
        }
    }
} 

public static DynamicDataFacet DynamicData(this Contact contact)
        {
            return contact.GetFacet<DynamicDataFacet>(DynamicDataFacet.DefaultFacetKey);
        }
namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
}

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

        private static XdbModel BuildModel()
        {
            XdbModelBuilder modelBuilder = new XdbModelBuilder("XYZ.Model.DynamicDataModel", new XdbModelVersion(1, 0));
            modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            modelBuilder.DefineFacet<Contact, DynamicDataFacet>(DynamicDataFacet.DefaultFacetKey);
            return modelBuilder.BuildModel();
        }
    }
}
namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
}

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

        private static XdbModel BuildModel()
        {
            XdbModelBuilder modelBuilder = new XdbModelBuilder("XYZ.Model.DynamicDataModel", new XdbModelVersion(1, 0));
            modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            modelBuilder.DefineFacet<Contact, DynamicDataFacet>(DynamicDataFacet.DefaultFacetKey);
            return modelBuilder.BuildModel();
        }
    }
} 

public static DynamicDataFacet DynamicData(this Contact contact)
        {
            return contact.GetFacet<DynamicDataFacet>(DynamicDataFacet.DefaultFacetKey);
        }
added 640 characters in body
Source Link
Foysal
  • 506
  • 2
  • 13
namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
} 

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

        private static XdbModel BuildModel()
        {
            XdbModelBuilder modelBuilder = new XdbModelBuilder("XYZ.Model.DynamicDataModel", new XdbModelVersion(1, 0));
            modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            modelBuilder.DefineFacet<Contact, DynamicDataFacet>(DynamicDataFacet.DefaultFacetKey);
            return modelBuilder.BuildModel();
        }
    }
}
namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
}
namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
} 

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

        private static XdbModel BuildModel()
        {
            XdbModelBuilder modelBuilder = new XdbModelBuilder("XYZ.Model.DynamicDataModel", new XdbModelVersion(1, 0));
            modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            modelBuilder.DefineFacet<Contact, DynamicDataFacet>(DynamicDataFacet.DefaultFacetKey);
            return modelBuilder.BuildModel();
        }
    }
}
More sample code added
Source Link
Foysal
  • 506
  • 2
  • 13

JSON:

{
  "Name": "XYZ.Model.DynamicDataModel",
  "Version": "1.0",
  "References": [
    {
      "Name": "XConnect",
      "Version": "1.0"
    },
    {
      "Name": "Sitecore.XConnect.Collection.Model",
      "Version": "9.0"
    }
  ],
  "Types": {
    "XYZ.Model.DynamicDataFacet": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "XYZ.Model.DynamicDataFacet, XYZ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "Data": {
          "Type": [
            "XYZ.Model.Data"
          ]
        }
      }
    },
    "XYZ.Model.Data": {
      "Type": "Complex",
      "ClrType": "XYZ.Model.Data, XYZ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "PropertyName": {
          "Type": "String"
        },
        "Type": {
          "Type": "String"
        },
        "Value": {
          "Type": "String"
        }
      }
    }
  },
  "Facets": [
    {
      "Target": "Contact",
      "Name": "DynamicData",
      "Type": "XYZ.Model.DynamicDataFacet"
    }
  ]
}

Model

namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
}

JSON:

{
  "Name": "XYZ.Model.DynamicDataModel",
  "Version": "1.0",
  "References": [
    {
      "Name": "XConnect",
      "Version": "1.0"
    },
    {
      "Name": "Sitecore.XConnect.Collection.Model",
      "Version": "9.0"
    }
  ],
  "Types": {
    "XYZ.Model.DynamicDataFacet": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "XYZ.Model.DynamicDataFacet, XYZ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "Data": {
          "Type": [
            "XYZ.Model.Data"
          ]
        }
      }
    },
    "XYZ.Model.Data": {
      "Type": "Complex",
      "ClrType": "XYZ.Model.Data, XYZ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "PropertyName": {
          "Type": "String"
        },
        "Type": {
          "Type": "String"
        },
        "Value": {
          "Type": "String"
        }
      }
    }
  },
  "Facets": [
    {
      "Target": "Contact",
      "Name": "DynamicData",
      "Type": "XYZ.Model.DynamicDataFacet"
    }
  ]
}

Model

namespace XYZ.Model
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class DynamicDataFacet : Facet
    {
        public const string DefaultFacetKey = "DynamicData";
        public List<Data> Data { get; set; }

        public DynamicDataFacet()
        {
            Data = new List<Data>();
        }
    }
}

namespace XYZ.Model
{
    [Serializable]
    public class Data
    {
        public string PropertyName { get; set; }
        public string Type { get; set; }
        public string Value { get; set; }
    }
}
Added sample code
Source Link
Foysal
  • 506
  • 2
  • 13
Loading
Source Link
Foysal
  • 506
  • 2
  • 13
Loading