This is a migrated thread and some comments may be shown as answers.

How to add and delete EF objects working with DataLoadMode="Asynchronous"?

1 Answer 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Peter Meinl
Top achievements
Rank 1
Peter Meinl asked on 11 Oct 2012, 01:45 PM
For easy coding we would like to use the DataGridViews feature DataLoadMode="Asynchronous" binding directly to the query.
Using this we do not need to manually code async EF I/O, the application does not block and by Binding the windows IsEnabled to the grids IsDirty we can easily block user input on the busy window.

If we use an ObservableCollection the I/O happens outside of the grid and thus is not async.
grid.ItemsSource = ObservableCollection(qry)

Without using an ObservableCollection I cannot get adds and deletes working.
For instance using grid.ItemsSource.Remove(grid.SelectedItem) plus db.RemoveObjet() seems not to work.

Is there an example for this scenario somewhere?

1 Answer, 1 is accepted

Sort by
0
Peter Meinl
Top achievements
Rank 1
answered on 17 Oct 2012, 07:18 AM
Because there was no answer to my question I assume the usability of DataLoadMode="Asynchronous" is limited to scenarios without ObservableCollections.

I implemented async loading manually:
Await Task.Factory.StartNew(
    Sub()
        qry.Load()
    'Local() returns a change tracked ObservableCollection
        grd.ItemsSource = _dbContext.Customers.Local
    End Sub, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext)


And use a RadBusyIndicator around the root Grid to disable then UI - the user can still move the active Window and use other Windows of the app without limitations.
<telerik:RadBusyIndicator">
    <Grid>
        ...
    </Grid>
</telerik:RadBusyIndicator>
Tags
GridView
Asked by
Peter Meinl
Top achievements
Rank 1
Answers by
Peter Meinl
Top achievements
Rank 1
Share this question
or