예제 #1
0
        /// <summary>
        /// Attaches a Bean to this bean in a manner of a 1:n reference. The Bean to attach
        /// has the Foreign key that references to this Bean's Id.
        /// If the Foreign Key Name of the (owned) Bean differs form the
        /// Name of the Owner Bean, it is possible to pass an alias name.
        /// </summary>
        /// <param name="bean">Bean to be attached. It references the current Bean via Foreign Key.</param>
        /// <param name="fkAlias">Alias for the Owner Bean's Foreign Key Name (w/o Primary Key Name)</param>
        /// <returns>true, if successful</returns>
        public bool AttachOwned(Bean bean, string fkAlias = "")
        {
            var foreignKey   = GetFkName(fkAlias == string.Empty ? GetKind() : fkAlias);
            var relatingKind = bean.GetKind();

            if (!Api.IsKnownKindColumn(relatingKind, foreignKey))
            {
                throw MissingForeignKeyColumnException.Create(relatingKind, foreignKey);
            }

            bean
            .Put(foreignKey, GetKeyValue())
            .Store();

            return(true);
        }