public ParentOneChild_Child(string text, ParentOneChild_Parent parent, ParentOneChild_ParentNullable?parentNullable, bool isStoring = true) { Key = StorageExtensions.NoKey; Text = text; Parent = parent; ParentNullable = parentNullable; #if DEBUG DC.Trace?.Invoke($"new ParentOneChild_Child: {ToTraceString()}"); #endif Parent.AddToChild(this); if (ParentNullable != null) { ParentNullable.AddToChild(this); } onConstruct(); if (DC.Data?.IsTransaction ?? false) { DC.Data.AddTransaction(new TransactionItem(11, TransactionActivityEnum.New, Key, this)); } if (isStoring) { Store(); } }
partial void onUpdating(string text, ParentOneChild_Parent parent, ParentOneChild_ParentNullable?parentNullable, ref bool isCancelled);
public void Update(string text, ParentOneChild_Parent parent, ParentOneChild_ParentNullable?parentNullable) { if (Key >= 0) { if (parent.Key < 0) { throw new Exception($"ParentOneChild_Child.Update(): It is illegal to add stored ParentOneChild_Child '{this}'" + Environment.NewLine + $"to Parent '{parent}', which is not stored."); } if (parentNullable?.Key < 0) { throw new Exception($"ParentOneChild_Child.Update(): It is illegal to add stored ParentOneChild_Child '{this}'" + Environment.NewLine + $"to ParentNullable '{parentNullable}', which is not stored."); } } var clone = new ParentOneChild_Child(this); var isCancelled = false; onUpdating(text, parent, parentNullable, ref isCancelled); if (isCancelled) { return; } #if DEBUG DC.Trace?.Invoke($"Updating ParentOneChild_Child: {ToTraceString()}"); #endif var isChangeDetected = false; if (Text != text) { Text = text; isChangeDetected = true; } if (Parent != parent) { Parent.RemoveFromChild(this); Parent = parent; Parent.AddToChild(this); isChangeDetected = true; } if (ParentNullable is null) { if (parentNullable is null) { //nothing to do } else { ParentNullable = parentNullable; ParentNullable.AddToChild(this); isChangeDetected = true; } } else { if (parentNullable is null) { ParentNullable.RemoveFromChild(this); ParentNullable = null; isChangeDetected = true; } else { if (ParentNullable != parentNullable) { ParentNullable.RemoveFromChild(this); ParentNullable = parentNullable; ParentNullable.AddToChild(this); isChangeDetected = true; } } } if (isChangeDetected) { onUpdated(clone); if (Key >= 0) { DC.Data.ParentOneChild_Children.ItemHasChanged(clone, this); } else if (DC.Data.IsTransaction) { DC.Data.AddTransaction(new TransactionItem(11, TransactionActivityEnum.Update, Key, this, oldItem: clone)); } HasChanged?.Invoke(clone, this); } #if DEBUG DC.Trace?.Invoke($"Updated ParentOneChild_Child: {ToTraceString()}"); #endif }