///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM IMMUTABLE OBJECT                 //////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="ConstraintDataKeySetMutableCore"/> class.
        /// </summary>
        /// <param name="immutable">
        /// The immutable. 
        /// </param>
        public ConstraintDataKeySetMutableCore(IConstraintDataKeySet immutable)
            : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConstrainedDataKeyset))
        {
            this.constrainedKeys = new List<IConstrainedDataKeyMutableObject>();

            foreach (IConstrainedDataKey each in immutable.ConstrainedDataKeys)
            {
                this.constrainedKeys.Add(new ConstrainedDataKeyMutableCore(each));
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECT                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ConstrainedDataKeyCore"/> class.
        /// </summary>
        /// <param name="mutable">
        /// The mutable. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        public ConstrainedDataKeyCore(IConstrainedDataKeyMutableObject mutable, IConstraintDataKeySet parent)
            : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConstrainedDataKey), parent)
        {
            this._keyValues = new List<IKeyValue>();

            foreach (IKeyValue each in mutable.KeyValues)
            {
                this._keyValues.Add(new KeyValueImpl(each.Code, each.Concept));
            }

            this.Validate();
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2.1 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="ConstrainedDataKeyCore"/> class.
        /// </summary>
        /// <param name="dataKeyType">
        /// The data key type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public ConstrainedDataKeyCore(DistinctKeyType dataKeyType, IConstraintDataKeySet parent)
            : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConstrainedDataKey), parent)
        {
            this._keyValues = new List<IKeyValue>();

            foreach (DinstinctKeyValueType componentValueSet in dataKeyType.GetTypedKeyValue<DinstinctKeyValueType>())
            {
                string concept = componentValueSet.id;
                if (componentValueSet.Value == null || componentValueSet.Value.Count < 1
                    || componentValueSet.Value.Count > 1)
                {
                    throw new SdmxSemmanticException("KeyValue expected to contain a single value");
                }

                string valueren = componentValueSet.Value[0].TypedValue;
                this._keyValues.Add(new KeyValueImpl(valueren, concept));
            }

            this.Validate();
        }
        /// <summary>
        /// Adds cross references for a constraint key to components map.
        /// </summary>
        /// <param name="constraintBean">
        /// The constraint object
        /// </param>
        /// <param name="returnReferences">
        /// The returned references
        /// </param>
        /// <param name="componentMap">
        /// The components map
        /// </param>
        /// <param name="constraintDataKey">
        /// The constraint data key
        /// </param>
        private void AddCrossReferencesForConstraintKey(IContentConstraintObject constraintBean,
                                                        ISet<ICrossReference> returnReferences,
                                                        IDictionary<String, IComponent> componentMap,
                                                        IConstraintDataKeySet constraintDataKey)
        {
            if (constraintDataKey == null)
                return;

            IDictionary<string, ISet<string>> componentCodeMap = new Dictionary<string, ISet<string>>();
            foreach (IConstrainedDataKey cdk in constraintDataKey.ConstrainedDataKeys)
            {
                foreach (IKeyValue kv in cdk.KeyValues)
                {
                    ISet<string> componentCodes = componentCodeMap[kv.Concept];
                    if (componentCodes == null)
                    {
                        componentCodes = new HashSet<String>();
                        componentCodeMap.Add(kv.Concept, componentCodes);
                    }
                    componentCodes.Add(kv.Code);
                }
            }
            foreach (string currentComponentId in componentCodeMap.Keys)
            {
                ICrossReference codelistRef = GetCodelistReferenceForComponent(constraintBean, currentComponentId, componentMap);
                if (codelistRef == null)
                    return;
                AddCodeReferences(constraintBean, returnReferences, codelistRef, componentCodeMap[currentComponentId]);
            }
        }