17,747
社区成员




Customer customer1 ; //已准备好的Customer对象
context.Order.Load(); //载入所有Order表中的数据
//此时可以双向绑定所有order显示,但我需要的是前面customer1对象下的所有orders
orderBindingSource.DataSource = context.Order.Local().ToBindingList();
//直接如下绑定,无法双向绑定,且无法新增(Fix Size)
orderBindingSource.DataSource = customer1.Orders;
//如下绑定,显示是正确的,但无法双向绑定
orderBindingSource.DataSource = context.Order.Local().Where(m=>m.CustomerID == customer1.ID);
orderBindingSource.Filter = string.Format("CustomerID = '{0}'",customer1.ID)
也不行。通过对象服务,您可以将控件(如 ComboBox、ListView 和 DataGridView 控件)绑定到 EntityCollection 或执行 ObjectQuery 时所返回的 ObjectResult。这两个实体框架类都实现用于数据绑定的 IListSource 接口。所有实体对象都派生自 StructuralObject 基类,该基类实现 INotifyPropertyChanged。这样便可在对象属性和控件之间实现双向数据绑定,从而将对控件的更新传播回绑定对象的属性。 - - MSDN