IsNewViaDataBinding / CancelEdit issue

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 04-Dec-2012 19:11:58   

1) EntityCollection<T>.AddNew() sets IsNewViaDataBinding = true

2) CancelEdit removes Entities from their parent collection where IsNewViaDataBinding = true

So the New child entities which I lovingly created using AddNew way before it got anywhere near a grid are now being deleted each time I press ESC in the grid. smile

I can't follow how, where or why _editCycleInProgress/_pendingCancelEdit get used but why is AddNew on a plain EntityCollectionBase2 making the assumption it is being called via databinding?

Surely databinding would only arrive in AddNew via an EntityView2 in which case EntityView2 could have had its own special internal method which does the same then sets that flag?

I could use Add instead of AddNew but I override AddNew so that I can call a custom UseDefaultValuesForNewEntity() method.

Adapter; v3.5.12.0330;

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Dec-2012 06:39:43   

AddNew is for databinding purposes (ref...), so that behavior is expected.

simmotech wrote:

I could use Add instead of AddNew but I override AddNew so that I can call a custom UseDefaultValuesForNewEntity() method.

What exactly are you doing in UseDefaultValuesForNewEntity, and where it's called? Maybe it could be a workaround using .Add instead.

David Elizondo | LLBLGen Support Team
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 05-Dec-2012 11:50:01   

AddNew is for databinding purposes (ref...), so that behavior is expected.

Well not by me. smile

IBindingList.AddNew() sure but not a public method. Anyway, it is what it is, I will add a CreateNew() method that calls AddNew then resets the flag by reflection.

UseDefaultValuesForNewEntity, I use this to put in default values for non-nullable fields:

        public virtual void UseDefaultValuesForNewEntity()
        {
            if (!IsNew) return;

            foreach(var field in Fields)
            {
                if (!field.IsChanged && !field.IsNullable && !field.IsPrimaryKey && !field.IsReadOnly)
                {
                    field.CurrentValue = TypeDefaultValue.GetDefaultValue(field.RealDataType);

                    Fields.IsDirty = true;
                }
            }
        }