views:

13

answers:

0

I have a RadGrid that uses EntityDataSource bound to Customer table in Northwind. It is the basic auto-everything setup.

This code will give the following error after editing the data and clicking Update in the edit form:

The object is in a detached state. This operation cannot be performed on an ObjectStateEntry when the object is detached.

What would be necessary to be able to detach and re-attach the object? I've simplified here because I am doing other operations on the object where I need it detached first.

protected void EntityDataSource1_Updating(object sender, EntityDataSourceChangingEventArgs e)
    {
                Customer c = (Customer)e.Entity;
                context.Detach(c);
                context.Attach(c);
    }

protected void EntityDataSource1_ContextCreating(object sender, EntityDataSourceContextCreatingEventArgs e)
        {
            e.Context = context;
        }

protected void EntityDataSource1_ContextDisposing(object sender, EntityDataSourceContextDisposingEventArgs e)
        {
            e.Cancel = true;
        }