I have a WinForms application which is using Entity Framework to query a database. The query pulls all of the records from a table, as well as all of the records from an associated table. I am assigning the results of the parent table to a BindingSource and assigning that to another BindingSource to access the child records. The parent BindingSource is bound to a ComboBox and the child BindingSource is bound to a DataGridView. This all works as expected.
My problem is this: at a certain point, I need to implement a refresh feature to pull down all of the records from the database to refresh the view. I have this currently working, but it only refreshes the parent records, not the child records.
The only success I’ve had at getting the desired behavior is to use ObjectQuery.Execute using the MergeOption.NoTracking option. This refreshes both the parent and child records, but if I’m not mistaken, I lose all tracking.
How can I have the child records updated as well? I’ve attempted to use the Include method and specified the child records table, but that had no impact.
The best option is simply creating new context rebind your controls and execute query again. Refreshing entities is mostly for resolving concurrency issues not of maintaining long living contexts.
If you want to refresh relations as well you must configure entity set for relations to support refresh. Currently you most probably configure only current object set or object query which will set the behavior only for the main entity: