Пример #1
0
        /// <summary>
        /// Attaches an owner Bean in a Manner of a 1:n relation. The owner
        /// represents the "1"-side of this relation. 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">Owner 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 AttachOwner(Bean bean, string fkAlias = "")
        {
            var foreignKey = GetFkName(fkAlias == string.Empty ? bean.GetKind() : fkAlias);

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

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

            return(true);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Detaches the owner ("1"-side of a 1:n relation) from the current Bean.
        /// Only the owner Kind is needed, here. The current (owned or "n"-side) Bean
        /// may be deleted or retained 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="ownerKind">Name of the owner Bean.</param>
        /// <param name="trashOwned">Deletes the current Bean when owner is detached</param>
        /// <param name="fkAlias"></param>
        /// <returns></returns>
        public bool DetachOwner(string ownerKind, bool trashOwned = false, string fkAlias = "")
        {
            if (trashOwned)
            {
                Trash();
            }
            else
            {
                var foreignKey = GetFkName(fkAlias == string.Empty ? ownerKind : fkAlias);

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

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

            return(true);
        }
Пример #4
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);
        }