public static bool Save(EntityCollection<PaymentRequestEntity> payments)
{
bool success = true;
List<PaymentRequestEntity> dirtyPayments = payments.DirtyEntities;
using (CoreDataAccessAdapter adapter = new CoreDataAccessAdapter())
{
try
{
PredicateExpression updateRestriction;
adapter.StartTransaction(System.Data.IsolationLevel.ReadCommitted, "Update Status");
foreach (PaymentRequestEntity payment in dirtyPayments)
{
updateRestriction = new PredicateExpression(
PaymentRequestFields.UpdateDate == payment.UpdateDate);
updateRestriction.Add(PaymentRequestFields.UpdateBy == payment.UpdateBy);
if (!adapter.SaveEntity(payment,
true,
updateRestriction))
{
success = false;
break;
}
}
}
catch
{
success = false;
throw;
}
finally
{
if (success)
{
adapter.Commit();
}
else
{
adapter.Rollback();
}
}
}
return success;
}
I get dirtyPayments.Count number of updates after the first call to adapter.SaveEntity. Basically all the dirty entities are updated on the first call, and to make it worse the updateRestriction is only included on the first update statement. It seems that the whole underlying collection is being saved when the first entity is saved. Any help will be appreciated.