Hi Danjal,
Regarding the new entity not showing in the grid:
You are binding to a RelatedEntityList, so you must set the relation entity or FK.
However, it looks like assigning values in the DataGridEventArgs is not updating the entity itself. You can see that the entity was Added, but all values you assigned in code (i.e. action.p_type = 13;) are actually null. This might be a bug in C1DataGrid. (you might want to check C1DataGrid documentation and/or report it to ComponentOne)
Regarding the "An entity with this key: EntMyAction: 0 already exists in this EntityManager" error:
I suggest generating the id of the entity. (i.e. mgr.GenerateID(entity, Entity.PropertyMetadata.EntityID); )
Remember that I mentioned earlier that values assigned to the DatagridEventArgs are not reflected in the entity itself, you you will need to get a hold of the entity to be able to properly assign values:
private void c1DataGrid_CommittedNewRow(object sender, C1.Silverlight.DataGrid.DataGridRowEventArgs e) {
// this will not work:
//_mgr.GenerateId((Order)e.Row.DataItem, Order.PropertyMetadata.OrderID);
// working directly with the entity will work:
var query = EntityQueryBuilder.BuildQuery(new EntityKey[] { ((Order)e.Row.DataItem).EntityAspect.EntityKey });
Order order = (Order)query.With(QueryStrategy.CacheOnly).FirstOrNullEntity();
_mgr.GenerateId(order, Order.PropertyMetadata.OrderID);
}
While working with C1DataGrid I also found out that calling SaveChangesAsync() will cause an "IdGenerator problem - not all temp ids converted to permanent ids" error. Calling ForceIdFixupAsync() will cause the same issue. A workaround is doing a partial save:
var entitiesToSave = _mgr.FindEntities(EntityState.AnyAddedModifiedOrDeleted);
_mgr.SaveChangesAsync(retrievedEntities);
or, if you want to save the new row immediatelly after commiting it:
private void c1DataGrid_CommittedNewRow(object sender, C1.Silverlight.DataGrid.DataGridRowEventArgs e) {
// code as posted above
// ...
_mgr.SaveChangesAsync(new Order[] { order });
}
Regards,
Silvio.