Hello,
I would like to get some clarity on when the different update methods should be used when working with the LinqDataAdapter. I’d been using the BeginUpdate/EndUpdate methods for everything, and then, accidentally, I found out that I didn’t need to, . That’s why I’m asking.
Scenario 1: The Linq query directly returns the Table Definition objects.
// Get data
var orders = this._dataModule.DataAdapter.GetTable<Orders>();
var order = orders.Where(o => o.Id == 1106).ToList().FirstOrDefault();
// Update objects
order.OrderStatus += 1;
// Apply changes
this._dataModule.DataAdapter.ApplyChanges();
In this case, since the object was returned from a direct Linq query, I don’t need to call DataAdapter.Update(order) or Order.BeginUpdate/Order.EndUpdate.
In this scenario, when using SendReducedDeltas, are only the deltas from fields changed sent or all the fields are considered as changed?
Scenario 2: The objects being changed are not returned directly by the Linq query
For example, in this query (taken from this question):
// Aliases to make the query cleaned
// These assignments do not cause any data request operations
var orders = this._dataModule.DataAdapter.GetTable<Orders>();
var orderDetails = this._dataModule.DataAdapter.GetTable<OrderDetails>();
var products = this._dataModule.DataAdapter.GetTable<Products>();
var query = orders
.Where(o => o.OrderStatus != 128)
.Join(orderDetails,
o => o.Id,
od => od.OrderId,
(order, details) => new { Order = order, Details = details })
.ToList()
.Select(g => g)
.GroupBy(g => g.Order)
.Select(g =>
{
g.Key.Details = g.Select(r => r.Details).ToList();
return g.Key;
});
In this case, the object was not directly returned by the Linq query, but instead, it was created by LinqToObject after retrieving the data, so I DO need to use the Update method:
// Update objects
order.OrderStatus += 1;
this._dataModule.DataAdapter.Update(order);
// Apply changes
this._dataModule.DataAdapter.ApplyChanges();
In this scenario, when using SendReducedDeltas, are only the deltas from fields changed sent or all the fields are considered as changed?
Is this correct?
And finally, under what circumstances do I need to use Order.BeginUpdate and Order.EndUpdate(DataAdapter) or Order.CancelChanges?
Thanks,
Arturo