public override void UpdatedAllRelated(TForeignEntity ForeignEntity) { TForeignKey?foreignKey = foreignKeyManager.GetEntityKey(ForeignEntity); if (propRelated != null) { EntityCollection <TForeignEntity, TRelatedEntity> relatedCollection = getRColc(ForeignEntity); foreach (TRelatedEntity RelatedEntity in relatedCollection) { // when an unchanged entity reference to added entity it's state change from unchanged to modified, // therefore when insert added entity to database, any related entity can be added or modified. if (RelatedEntity.HasBusy() || !RelatedEntity.HasChanged()) { throw new EntityRelationManagerException($"[{this}] UpdatedAllRelated Failed, {RelatedEntity} With {RelatedEntity.State} State Is Not Supported"); } setFKey(RelatedEntity, foreignKey); RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignKey.Name); RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; } } else { foreach (TRelatedEntity RelatedEntity in relatedEntitySet) { TForeignEntity foreignEntity = getFRef(RelatedEntity); if (foreignEntity == ForeignEntity) { // when an unchanged entity reference to added entity it's state change from unchanged to modified, // therefore when insert added entity to database, any related entity can be added or modified. if (RelatedEntity.HasBusy() || !RelatedEntity.HasChanged()) { throw new EntityRelationManagerException($"[{this}] UpdatedAllRelated Failed, {RelatedEntity} With {RelatedEntity.State} State Is Not Supported"); } setFKey(RelatedEntity, foreignKey); RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignKey.Name); RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; } } } }
public override void UpdatedAllOrphan(TForeignEntity ForeignEntity) { TForeignKey foreignKey = foreignKeyManager.GetEntityKey(ForeignEntity); if (propRelated != null) { EntityCollection <TForeignEntity, TRelatedEntity> relatedCollection = getRColc(ForeignEntity); foreach (TRelatedEntity RelatedEntity in orphanage.GetAllRelated(foreignKeyManager.GetEntityKey(ForeignEntity)).ToArray()) { 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); relatedCollection.InternalAdd(RelatedEntity); RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; } } else { foreach (TRelatedEntity RelatedEntity in orphanage.GetAllRelated(foreignKeyManager.GetEntityKey(ForeignEntity)).ToArray()) { 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; } } }
public override void RestoreAllRelated(TForeignEntity ForeignEntity) { TForeignKey?foreignKey = foreignKeyManager.GetEntityKey(ForeignEntity); if (propRelated != null) { EntityUnique <TForeignEntity, TRelatedEntity> relatedUnique = getRUniq(ForeignEntity); TRelatedEntity RelatedEntity = relatedUnique.Entity; if (!RelatedEntity.IsNull()) { UpdateUniqueConstraint(foreignKey, getFKey(RelatedEntity)); setFKey(RelatedEntity, foreignKey); RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignKey.Name); RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; } } else { foreach (TRelatedEntity RelatedEntity in relatedEntitySet) { TForeignEntity foreignEntity = getFRef(RelatedEntity); if (foreignEntity == ForeignEntity) { UpdateUniqueConstraint(foreignKey, getFKey(RelatedEntity)); setFKey(RelatedEntity, foreignKey); RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignKey.Name); RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; break; } } } }
public override void NotifyAllRelated(TForeignEntity ForeignEntity) { if (propRelated != null) { EntityUnique <TForeignEntity, TRelatedEntity> relatedUnique = getRUniq(ForeignEntity); TRelatedEntity RelatedEntity = relatedUnique.Entity; if (!RelatedEntity.IsNull()) { if (!RelatedEntity.HasEditable() || RelatedEntity.HasBusy()) { throw new EntityRelationManagerException($"[{this}] NotifyAllRelated Failed, {RelatedEntity} With {RelatedEntity.State} State Is Not Supported"); } RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; } } else { foreach (TRelatedEntity RelatedEntity in relatedEntitySet) { TForeignEntity foreignEntity = getFRef(RelatedEntity); if (foreignEntity == ForeignEntity) { if (!RelatedEntity.HasEditable() || RelatedEntity.HasBusy()) { throw new EntityRelationManagerException($"[{this}] NotifyAllRelated Failed, {RelatedEntity} With {RelatedEntity.State} State Is Not Supported"); } RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; break; } } } }
public override void RestoreAllRelated(TForeignEntity ForeignEntity) { TForeignKey?foreignKey = foreignKeyManager.GetEntityKey(ForeignEntity); if (propRelated != null) { EntityCollection <TForeignEntity, TRelatedEntity> relatedCollection = getRColc(ForeignEntity); foreach (TRelatedEntity RelatedEntity in relatedCollection) { setFKey(RelatedEntity, foreignKey); RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignKey.Name); RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; } } else { foreach (TRelatedEntity RelatedEntity in relatedEntitySet) { TForeignEntity foreignEntity = getFRef(RelatedEntity); if (foreignEntity == ForeignEntity) { setFKey(RelatedEntity, foreignKey); RelatedEntity.State |= EntityState.Busy; RelatedEntity.OnPropertyChanged(propForeignKey.Name); RelatedEntity.OnPropertyChanged(propForeignReference.Name); RelatedEntity.State ^= EntityState.Busy; } } } }