Llblgen 5.7/Adapter/WPF
Telerik's grid (and maybe others) allow you to intercept the adding of new entities, in Telerik's case this is done by hooking the AddingNewDataItem
event. In the handler you can supply the entity you want added with something like this (dummy example as it does nothing worthwhile)
public void AddingNewDataItem(object sender, GridViewAddingNewEventArgs args)
{
args.NewObject = new SomeEntity();
}
However, this throw the exception with message
Add a new object to the related collection instead, or use IBindingList.AddNew() on this object.
with the stack
at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase
1.System.Collections.IList.Add(Object value)
at Telerik.Windows.Data.QueryableCollectionView.AddItemToSourceList(Object newItem, IList sourceList)
at Telerik.Windows.Data.QueryableCollectionView.AddItemToSource(Object newItem)
at Telerik.Windows.Data.QueryableCollectionView.AddNewInternal(Object newItem)
at Telerik.Windows.Data.QueryableCollectionView.AddNew(Object newItem)
at Telerik.Windows.Data.QueryableCollectionView.AddNewItem(Object newItem)
at Telerik.Windows.Data.DataItemCollection.AddNew(Object newItem)
at Telerik.Windows.Controls.GridView.GridViewDataControl.CreateNewItem()
at Telerik.Windows.Controls.GridView.GridViewDataControl.ShowInsertRowIfNeeded(Nullable1 position)
at Telerik.Windows.Controls.GridView.GridViewDataControl.BeginInsert()
at Telerik.Windows.Controls.GridView.GridViewNewRow.HandleUserInteraction()
at Telerik.Windows.Controls.GridView.GridViewNewRow.OnMouseLeftButtonDown(MouseButtonEventArgs e)
Sure enough IList.Add implementation is not implemented in EntityViewBase:
/// <summary>
/// Not supported. Use AddNew() or add a new object to the related entity collection.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
int IList.Add( object value )
{
if( value == null )
{
// design time databinding.
IEntityCore newEntity = this.AddNew();
return this.IndexOf((TEntity)newEntity);
}
throw new NotSupportedException( "Add a new object to the related collection instead, or use IBindingList.AddNew() on this object." );
}
How should the EntityCollections be bound to allow this?
Current workaround I have is to use an ObservableCollection<>.