【发布时间】:2014-11-12 13:03:30
【问题描述】:
我对进行这些更改感到非常困惑。
假设我们在数据库中有一个表,我们称之为Customers。
我们使用实体框架从表中获取数据,如下所示:
List<Customers> customers = context.Customers.ToList();
我们还有一个BindingSource,我们使用List<Customers作为数据源:
bindingSource1.DataSource = customers;
最后,我们将绑定源分配为DataGridView的数据源:
dataGridView1.DataSource = bindingSource1;
现在假设我们要添加一个新客户。对数据执行添加/更改的正确方法是什么?我们是否应该添加/更新List<Customers>,最后只保存上下文?
同时,取消更改的正确方法是什么?假设我们使用这里提到的一些建议: How to Refresh DbContext 和这里: https://code.msdn.microsoft.com/How-to-undo-the-changes-in-00aed3c4
当上下文中的更改被取消(所有修改、删除和添加的条目都被取消)时,我们如何更新DataGridView或BindingSource?
我想我错过了一块拼图。
【问题讨论】:
标签: c# entity-framework datagridview entity-framework-4 bindingsource