I'm updating a WindowsForms app (Self Servicing using SQL Server 2005) from v1.0.2005.1 to v2.0. I have some forms which are data bound to the fields in an LLBLGen Pro entity, and which have the usual BindingSource and BindingNavigator. (These forms often don't have a grid on them, just individual data bound text fields, etc.)
In v1.0.2005.1 what worked for me was to define the "ABCEntityBindingSource_AddingNew(object sender, System.ComponentModel.AddingNewEventArgs e)" method, and have this method create a new ABCEntity and set its id (and other fields) to appropriate values, then assign it to e.NewObject. But when I run this on v2.0 and click the "Add" button in the binding navigator, I get NotSupportedException saying "Add a new object to the related collection instead, or use IBindingList.AddNew() on this object." (See below for stack trace).
After some experimentation, it looks like I may not need the ..._AddingNew() method in 2.0. Things seem to work without it, except that now I don't get a chance to set the id and other fields on the new entity, so when I later do a "Save", the id may be null. I think the correct way to solve this is to declare the id column in SQL Server to be "identity(1,1)", and in LLBLGen Pro on the Id field to set "Is Identity/Sequence field, Sequence Used SCOPE_IDENTITY()". I'm having a little trouble getting this to work correctly, as I still get exceptions that the id field is null.
What is the recommended way to do this? That is, how should I declare the id column in SQL Server, and what properties should I set on the id field in LLBLGen Pro?
Also, I have some other entities which have a composite key, consisting of an id and a version. This means that the id alone may not be unique (I could have id=1,version=1 and id=1,version=2), so I don't think I can declare id to be "identity(1,1)" for this entity.
Any advice would be much appreciated!
Thanks,
Wayne
System.NotSupportedException occurred
Message="Add a new object to the related collection instead, or use IBindingList.AddNew() on this object."
Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20"
StackTrace:
at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.Add(Object value)
at System.Windows.Forms.BindingSource.Add(Object value)
at System.Windows.Forms.BindingSource.AddNew()
at System.Windows.Forms.BindingNavigator.OnAddNew(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.I MsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at DataEntry2.Program.Main() in C:\DataEntry\Program.cs:line 15