Exemplo n.º 1
0
        /// <summary>
        ///     Adds a member to this type.
        /// </summary>
        /// <param name="member">The member to add.</param>
        /// <param name="forceAdd">
        ///     Indicates whether the addition is forced, regardless of
        ///     whether read-only is set.
        /// </param>
        /// <remarks>
        ///     Adding a NavigationProperty to an EntityType introduces a circular dependency between
        ///     EntityType and AssociationEndMember, which is worked around by calling this method.
        ///     This is the case of OneToOneMappingBuilder, in the designer. Must not be used in other context.
        /// </remarks>
        internal void AddMember(EdmMember member, bool forceAdd)
        {
            Check.NotNull(member, "member");

            if (!forceAdd)
            {
                Util.ThrowIfReadOnly(this);
            }

            if (DataSpace != member.TypeUsage.EdmType.DataSpace &&
                BuiltInTypeKind != BuiltInTypeKind.RowType)
            {
                throw new ArgumentException(
                          Strings.AttemptToAddEdmMemberFromWrongDataSpace(
                              member.Name,
                              this.Name,
                              member.TypeUsage.EdmType.DataSpace,
                              this.DataSpace),
                          "member");
            }

            // Since we set the DataSpace of the RowType to be -1 in the constructor, we need to initialize it
            // as and when we add members to it
            if (BuiltInTypeKind.RowType == BuiltInTypeKind)
            {
                // Do this only when you are adding the first member
                if (_members.Count == 0)
                {
                    DataSpace = member.TypeUsage.EdmType.DataSpace;
                }
                // We need to build types that span across more than one space. For such row types, we set the
                // DataSpace to -1
                else if (DataSpace != (DataSpace)(-1) &&
                         member.TypeUsage.EdmType.DataSpace != DataSpace)
                {
                    DataSpace = (DataSpace)(-1);
                }
            }

            if (_members.IsReadOnly && forceAdd)
            {
                _members.ResetReadOnly();
                _members.Add(member);
                _members.SetReadOnly();
            }
            else
            {
                _members.Add(member);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Adds a member to this type.
        /// </summary>
        /// <param name="member">The member to add.</param>
        /// <param name="forceAdd">
        ///     Indicates whether the addition is forced, regardless of
        ///     whether read-only is set.
        /// </param>
        /// <remarks>
        ///     Adding a NavigationProperty to an EntityType introduces a circular dependency between
        ///     EntityType and AssociationEndMember, which is worked around by calling this method.
        ///     This is the case of OneToOneMappingBuilder, in the designer. Must not be used in other context.
        /// </remarks>
        internal void AddMember(EdmMember member, bool forceAdd)
        {
            Check.NotNull(member, "member");

            if (!forceAdd)
            {
                Util.ThrowIfReadOnly(this);
            }

            Debug.Assert(
                DataSpace == member.TypeUsage.EdmType.DataSpace || BuiltInTypeKind == BuiltInTypeKind.RowType,
                "Wrong member type getting added in structural type");

            //Since we set the DataSpace of the RowType to be -1 in the constructor, we need to initialize it
            //as and when we add members to it
            if (BuiltInTypeKind.RowType == BuiltInTypeKind)
            {
                // Do this only when you are adding the first member
                if (_members.Count == 0)
                {
                    DataSpace = member.TypeUsage.EdmType.DataSpace;
                }
                // We need to build types that span across more than one space. For such row types, we set the
                // DataSpace to -1
                else if (DataSpace != (DataSpace)(-1) &&
                         member.TypeUsage.EdmType.DataSpace != DataSpace)
                {
                    DataSpace = (DataSpace)(-1);
                }
            }

            if (_members.IsReadOnly && forceAdd)
            {
                _members.ResetReadOnly();
                _members.Add(member);
                _members.SetReadOnly();
            }
            else
            {
                _members.Add(member);
            }
        }