コード例 #1
0
        /// <summary>
        /// Detaches a referencing Bean from the current Bean. The referencing bean
        /// may be trashed (deleted) or retained in the table but then as orphaned Bean.
        /// 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 detached.</param>
        /// <param name="trashOwned">Delete or retain Bean as orphaned Bean.</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 DetachOwned(Bean bean, bool trashOwned = false, string fkAlias = "")
        {
            if (trashOwned)
            {
                bean.Trash();
            }
            else
            {
                var foreignKey = GetFkName(fkAlias == string.Empty ? GetKind() : fkAlias);

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

                bean
                .Put(foreignKey, null)
                .Store();
            }

            return(true);
        }