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

Syncing DBContext and QueryableCollectionView

1 Answer 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 2
Mike asked on 08 Jul 2011, 12:11 PM
Hi,
i have a - maybe - stupid question. My Application uses Entity Framework 4.1 with DBContext. In the MainWindow is a RadGridView bound to a QueryableCollectionView (Customers) to display Data.

<telerik:RadGridView x:Name="uxCustomerGrid" ItemsSource="{Binding Customers,BindsDirectlyToSource=True}" IsReadOnly="True" EnableColumnVirtualization="True" EnableRowVirtualization="true" SelectionMode="Extended" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" GridLinesVisibility="None" IsFilteringAllowed="False" ShowGroupPanel="False" RowStyle="{DynamicResource CustomerRowStyle}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Kundennummer}" Header="Nummer"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Kundenname}" Header="Name" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Ort.Bezeichnung}" Header="Ort" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Ort.PLZ}" Header="PLZ" IsVisible="False" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Einwohneranzahl}" Header="Einwohner" IsVisible="False" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>

        private QueryableCollectionView _customers;
 
        public QueryableCollectionView Customers
        {
            get { return _customers; }
            set
            {
                if (value != _customers)
                {
                    _customers = value;
                    OnPropertyChanged("Customers");
                }
            }
        }
 
....
 
this._context = new MiexUnitOfWork();
_context.Kunde.ToList();
this.Customers = new QueryableCollectionView(_context.Kunde.Local);

The user changes a single row of the grid via a ModalWindow. The Window has it's own dbcontext. After the user has closed the ModalWindow (and the changes are saved to the database) i wan't to refresh the grid in the parent's window.
I tried the following:
_context.Entry(_context.Kunde.Find(Key)).Reload()

This code forces the dbcontext to update the changed entry. But the changes are not reflected in the grid. I tried to call the Refresh() method of the QueryableCollectionView, but the grid still show's the old values.

How can i force the grid to show the changes made in the dbcontext?

1 Answer, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 2
answered on 08 Jul 2011, 01:21 PM
Ok, forget about it. Just discovered, that the POCO's generated from the EF do not implement INotifyPropertyChanged. Changed the T4 template and now erverything works fine!
Tags
GridView
Asked by
Mike
Top achievements
Rank 2
Answers by
Mike
Top achievements
Rank 2
Share this question
or