Now the next break shows the exception I am interested in
Exception thrown: 'System.InvalidOperationException' in EntityFramework.dll
Additional information: Multiplicity constraint violated.
The role 'Account_Children_Source' of the relationship
'SBD.GL.Module.BusinessObjects.Account_Children' has multiplicity 1 or 0..1. occurred
The call stack is
EntityFramework.dll!System.Data.Entity.Core.Objects.EntityEntry.AddDetectedRelationship<System.Data.Entity.Core.Objects.Internal.IEntityWrapper>(System.Collections.Generic.Dictionary<System.Data.Entity.Core.Objects.Internal.IEntityWrapper,System.Collections.Generic.Dictionary<System.Data.Entity.Core.Objects.DataClasses.RelatedEnd,System.Collections.Generic.HashSet<System.Data.Entity.Core.Objects.Internal.IEntityWrapper>>> relationships, System.Data.Entity.Core.Objects.Internal.IEntityWrapper relatedObject, System.Data.Entity.Core.Objects.DataClasses.RelatedEnd relatedEnd) + 0x166 bytes
EntityFramework.dll!System.Data.Entity.Core.Objects.EntityEntry.AddRelationshipDetectedByGraph(System.Collections.Generic.Dictionary<System.Data.Entity.Core.Objects.Internal.IEntityWrapper,System.Collections.Generic.Dictionary<System.Data.Entity.Core.Objects.DataClasses.RelatedEnd,System.Collections.Generic.HashSet<System.Data.Entity.Core.Objects.Internal.IEntityWrapper>>> relationships, object relatedObject, System.Data.Entity.Core.Objects.DataClasses.RelatedEnd relatedEndFrom, bool verifyForAdd) + 0xb6 bytes
EntityFramework.dll!System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInRelationshipsOfSingleEntity() + 0x2a6 bytes
EntityFramework.dll!System.Data.Entity.Core.Objects.ObjectStateManager.DetectChangesInNavigationProperties(System.Collections.Generic.IList<System.Data.Entity.Core.Objects.EntityEntry> entries) + 0x4e bytes
EntityFramework.dll!System.Data.Entity.Core.Objects.ObjectStateManager.DetectChanges() + 0x52 bytes
EntityFramework.dll!System.Data.Entity.Core.Objects.ObjectContext.DetectChanges() + 0x14 bytes
DevExpress.ExpressApp.EF.v18.2.dll!DevExpress.ExpressApp.EF.EFObjectSpace.DetectChanges() Line 87 + 0xb bytes C#
DevExpress.ExpressApp.EF.v18.2.dll!DevExpress.ExpressApp.EF.EFObjectSpace.GetModifiedObjects() Line 93 C#
DevExpress.ExpressApp.EF.v18.2.dll!DevExpress.ExpressApp.EF.EFObjectSpace.ModifiedObjects.get() Line 440 + 0x6 bytes C#
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.SystemModule.CustomCollectModifiedObjectsEventArgs.CollectModifiedObjects(bool checkObjectSpaceIsModified) Line 150 + 0x15 bytes C#
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.SystemModule.LockController.GetModifiedObjects() Line 323 + 0x25 bytes C#
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.SystemModule.LockController.CheckLocking(DevExpress.ExpressApp.Win.SystemModule.LockController controller) Line 388 + 0x17 bytes C#
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.SystemModule.LockController.CheckLocking(object obj) Line 211 + 0x9 bytes C#
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.SystemModule.LockController.ViewObjectSpace_ObjectChanged(object sender, DevExpress.ExpressApp.ObjectChangedEventArgs e) Line 202 + 0x12 bytes C#
DevExpress.ExpressApp.v18.2.dll!DevExpress.ExpressApp.BaseObjectSpace.OnObjectChanged(DevExpress.ExpressApp.ObjectChangedEventArgs args) Line 122 + 0x9 bytes C#
DevExpress.ExpressApp.EF.v18.2.dll!DevExpress.ExpressApp.EF.EFObjectSpace.SetModified(object obj, DevExpress.ExpressApp.ObjectChangedEventArgs args) Line 371 C#
DevExpress.ExpressApp.v18.2.dll!DevExpress.ExpressApp.BaseObjectSpace.SetModified(object obj, DevExpress.ExpressApp.DC.IMemberInfo memberInfo) Line 802 + 0x34 bytes C#
DevExpress.ExpressApp.v18.2.dll!DevExpress.ExpressApp.DetailView.Editor_ControlValueChanged(object sender, System.EventArgs e) Line 83 + 0x38 bytes C#
DevExpress.ExpressApp.v18.2.dll!DevExpress.ExpressApp.Editors.PropertyEditor.OnControlValueChanged() Line 127 + 0x21 bytes C#
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.Editors.DXPropertyEditor.Editor_EditValueChanged(object sender, System.EventArgs e) Line 69 + 0xa bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChangedCore(System.EventArgs e) Line 1485 + 0x1b bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChanged(System.EventArgs e) Line 1481 + 0xc bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.BaseEdit.RaiseEditValueChanged() Line 1270 + 0x3d bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.BaseEdit.OnEditValueChanged() Line 1259 + 0xd bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.TextEdit.OnEditValueChanged() Line 1700 C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.BaseEdit.OnEditValueChanging(DevExpress.XtraEditors.Controls.ChangingEventArgs e) Line 1252 C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.TextEdit.OnEditValueChanging(DevExpress.XtraEditors.Controls.ChangingEventArgs e) Line 2069 C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.BaseEdit.EditValue.set(object value) Line 1196 + 0x44 bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.TextEdit.OnMaskBox_ValueChanged(object sender, System.EventArgs e) Line 1895 + 0x1e bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.RaiseEditTextChanged() Line 1208 + 0x2b bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.MaskStrategy.SimpleStrategy.DoAfterTextChanged(System.EventArgs e) Line 519 + 0x22 bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.OnTextChanged(System.EventArgs e) Line 1421 + 0x14 bytes C#
System.Windows.Forms.dll!System.Windows.Forms.TextBoxBase.WmReflectCommand(ref System.Windows.Forms.Message m) + 0xf7 bytes
System.Windows.Forms.dll!System.Windows.Forms.TextBoxBase.WndProc(ref System.Windows.Forms.Message m) + 0x42 bytes
System.Windows.Forms.dll!System.Windows.Forms.TextBox.WndProc(ref System.Windows.Forms.Message m) + 0x39 bytes
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.BaseWndProc(ref System.Windows.Forms.Message m) Line 285 + 0x21 bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.MaskStrategy.SimpleStrategy.DoWndProc(ref System.Windows.Forms.Message m) Line 528 + 0xf bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.WndProc(ref System.Windows.Forms.Message m) Line 1459 + 0x15 bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.TextBoxMaskBox.WndProc(ref System.Windows.Forms.Message msg) Line 1042 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x13 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x35 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x80 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Control.SendMessage(int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x21 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ReflectMessageInternal(System.IntPtr hWnd, ref System.Windows.Forms.Message m) + 0x3b bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmCommand(ref System.Windows.Forms.Message m) + 0x1b bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x3b9 bytes
DevExpress.Utils.v18.2.dll!DevExpress.Utils.Controls.ControlBase.WndProc(ref System.Windows.Forms.Message m) Line 185 + 0x21 bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.TextEdit.WndProc(ref System.Windows.Forms.Message msg) Line 1446 + 0x1a bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x13 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x35 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x80 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) + 0x56 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.DefWndProc(ref System.Windows.Forms.Message m) + 0xf bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmKeyChar(ref System.Windows.Forms.Message m) + 0x2c bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x88a bytes
System.Windows.Forms.dll!System.Windows.Forms.TextBoxBase.WndProc(ref System.Windows.Forms.Message m) + 0x37 bytes
System.Windows.Forms.dll!System.Windows.Forms.TextBox.WndProc(ref System.Windows.Forms.Message m) + 0x39 bytes
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.BaseWndProc(ref System.Windows.Forms.Message m) Line 285 + 0x21 bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.MaskStrategy.SimpleStrategy.DoWndProc(ref System.Windows.Forms.Message m) Line 528 + 0xf bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.Mask.MaskBox.WndProc(ref System.Windows.Forms.Message m) Line 1459 + 0x15 bytes C#
DevExpress.XtraEditors.v18.2.dll!DevExpress.XtraEditors.TextBoxMaskBox.WndProc(ref System.Windows.Forms.Message msg) Line 1042 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x13 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x35 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x80 bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) + 0x24d bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x15f bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x4c bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.Run() + 0x2e bytes
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.WinApplication.DoApplicationRun() Line 412 + 0x5 bytes C#
DevExpress.ExpressApp.Win.v18.2.dll!DevExpress.ExpressApp.Win.WinApplication.Start() Line 652 C#
> SBD.GL.Win.exe!SBD.GL.Win.Program.Main() Line 45 + 0xa bytes C#
Hmm something to do with self referencing
I already had the
[InverseProperty("Parent")]
set on the Children but I experimented with putting the relationship in the OnModelCreating instead.
It made no difference.
I think about this old post
https://www.devexpress.com/Support/Center/Question/Details/T289297/how-do-i-initialise-a-child-record-with-it-s-parent-link
It turns out there is no need to do this because I am using the [Aggregated] attribute
private void controller_ObjectCreated(object sender, ObjectCreatedEventArgs e)
{
var detailView = ObjectSpace.Owner as DetailView;
if (!(detailView?.CurrentObject is Account parent)) return;
var child = e.CreatedObject as Account;
if (child.Parent.Id == parent.Id)
{
Console.WriteLine("The parent is already set"); // arrives here
}
child.Parent = parent; // no need to do this
However it seems , when I experiment, that I can solve my problem by removing the aggregated tag , in which case I will need to use the controller.