Ejemplo n.º 1
0
        public override void UpdatedAllOrphan(TForeignEntity ForeignEntity)
        {
            TForeignKey foreignKey = foreignKeyManager.GetEntityKey(ForeignEntity);

            if (propRelated != null)
            {
                EntityUnique <TForeignEntity, TRelatedEntity> relatedUnique = getRUniq(ForeignEntity);

                TRelatedEntity RelatedEntity = orphanage.Count(foreignKey) == 1 ? orphanage.GetAllRelated(foreignKey).ToArray()[0] : default;

                if (!RelatedEntity.IsNull()) // orphanage.Count != 0
                {
                    if (!RelatedEntity.HasEditable() || RelatedEntity.HasBusy())
                    {
                        throw new EntityRelationManagerException($"[{this}] UpdatedAllOrphan Failed, {RelatedEntity} With {RelatedEntity.State} State Is Not Supported");
                    }

                    // UpdatedOrphan ....
                    setFRef(RelatedEntity, ForeignEntity);
                    OrphanageRemove(RelatedEntity, foreignKey);

                    relatedUnique.InternalSet(RelatedEntity);

                    RelatedEntity.State |= EntityState.Busy;

                    RelatedEntity.OnPropertyChanged(propForeignReference.Name);

                    RelatedEntity.State ^= EntityState.Busy;
                }
            }
            else
            {
                TRelatedEntity RelatedEntity = orphanage.Count(foreignKey) == 1 ? orphanage.GetAllRelated(foreignKey).ToArray()[0] : default;

                if (!RelatedEntity.IsNull()) // orphanage.Count != 0
                {
                    if (!RelatedEntity.HasEditable() || RelatedEntity.HasBusy())
                    {
                        throw new EntityRelationManagerException($"[{this}] UpdatedAllOrphan Failed, {RelatedEntity} With {RelatedEntity.State} State Is Not Supported");
                    }

                    // UpdatedOrphan ....
                    setFRef(RelatedEntity, ForeignEntity);
                    OrphanageRemove(RelatedEntity, foreignKey);

                    RelatedEntity.State |= EntityState.Busy;

                    RelatedEntity.OnPropertyChanged(propForeignReference.Name);

                    RelatedEntity.State ^= EntityState.Busy;
                }
            }
        }
Ejemplo n.º 2
0
        private protected override void RelatedRemove(TRelatedEntity RelatedEntity, TForeignEntity ForeignEntity)
        {
            if (propRelated != null)
            {
                EntityUnique <TForeignEntity, TRelatedEntity> relatedUnique = getRUniq(ForeignEntity);
#if Test || Test2
                if (relatedUnique == null)
                {
                    throw new TestException($"[{this}] RelatedRemove Failed, {ForeignEntity} {typeof(TForeignEntity).Name}.{propRelated.Name} Is Null");
                }
#endif
                relatedUnique.InternalSet(default(TRelatedEntity));
            }
        }