Reputation: 141
Example Model: Customer -> Order
contex.Order.Load();
orderBindingSource.DataSource = context.Order.Local().ToBindingList();
Then, how to filter? e.g. context.Order.Where(m=>m.customerID > 1)
I want to get the BindingList implementation that stays in sync with the ObservableCollection returned by the Local property.
Upvotes: 14
Views: 3767
Reputation: 1728
I think the best way. Is using load, you can see the details https://learn.microsoft.com/en-us/ef/ef6/querying/local-data You can use Load or best loadAsync like the example
dbContext.Order.Where(m=>m.customerID > 1).LoadAsync().ContinueWith(loadTask =>
{
// Bind data to control when loading complete
orderBindingSource.DataSource = dbContext.Order.Local.ToBindingList();
}, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
Upvotes: 0
Reputation: 82337
Have you tried using select?
contex.Order.Load();
orderBindingSource.DataSource =
context.Order.Local().Select( m => m.customerID > 1).ToBindingList();
Edit
Not entirely sure about this, it compiles but I do not have a full environment to test it. Perhaps if you try to load in the specific data, and then you can access it in local for the binding list. Like this:
context.Order.Select( m => m.customerID > 1).Load();
orderBindingSource.DataSource =
context.Order.Local.ToBindingList();
Upvotes: 4