Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of modified objects in Entity Framework 5

Tags:

I'm binding list of entities to a data grid view like this:

var orders = context.Order.ToList();  BindingList<Order> orderList = new BindingList<Order>(orders);  dataGridView1.DataSource = orderList; 

User can edit or add new directly on datagridview. When user click Save button, in order to optimize performance, I want to retrieve list of entities that has been changed/new to perform insert/update. How can I achieve this?

EDIT Define add new row to gridview:

BindinList<Order> orders = (BindingList<Order>)dataGridView1.Datasource;  order.Add(new Order()); 

EDIT 2 Solve:

BindinList<Order> orders = (BindingList<Order>)dataGridView1.Datasource;  Order order = new Order();  context.Order.Add(order);  order.Add(order);