[dba-VB] CodeFirst, DataBinding and audit trailing deleted items on client side

Salakhetdinov Shamil mcp2004 at mail.ru
Tue Apr 16 20:44:41 CDT 2013


 Sample code Part II - it has to be "glued" with Part I:

// traces individual editions and deletions
private void _entityBindingSource_ListChanged(object sender, ListChangedEventArgs e)
{
if (_loadInProgress) return;
auditTrailModelChanges(ref _auditTrailItems);
}
// traces individual deletions
private void _entityDataGridView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
{
if (_loadInProgress) return;
auditTrailModelChanges(ref _auditTrailItems);
}
private string getKeyValue(T item)
{
return (string)_context.Entry(item).Property(_altKeyFieldName).CurrentValue; 
}
private int getIDValue(T item)
{
return (int)_context.Entry(item).Property(_idFieldName).CurrentValue;
}
void IDisposable.Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_entityBindingSource != null)
_entityBindingSource.ListChanged -= new ListChangedEventHandler(_entityBindingSource_ListChanged);
if (_entityDataGridView != null)
_entityDataGridView.RowsRemoved -= new DataGridViewRowsRemovedEventHandler(_entityDataGridView_RowsRemoved);
}
}
// saves changes and returns actual set of data changes
public Dictionary<string, AuditTrailItem> SaveChanges()
{
var batchAuditTrailItems = new Dictionary<string, AuditTrailItem>();
auditTrailModelChanges(ref batchAuditTrailItems);
_context.SaveChanges();
return batchAuditTrailItems; 
}
//+ debug/test
#if DEBUG
public IEnumerable<string> GetAuditTrailItemsTestReportString(Dictionary<string, AuditTrailItem> auditTrailItems)
{
foreach (var textLine in this.GetAuditTrailItemsTestReport(auditTrailItems))
{
yield return textLine + System.Environment.NewLine;
}
}
public List<string> GetAuditTrailItemsTestReport(Dictionary<string, AuditTrailItem> auditTrailItems)
{
if (auditTrailItems == null) return new List<string>();
List<string> report = new List<string>();
foreach (var auditTrailItem in auditTrailItems.Values)
{
report.Add(
string.Format(
" {0}: ID = '{1}', Name = '{2}'\n",
auditTrailItem.ItemState.ToString(),
getIDValue(auditTrailItem.Item), getKeyValue(auditTrailItem.Item)));
}
return report;
}
#endif
//- debug/test
}
}
Среда, 17 апреля 2013, 5:39 +04:00 от Salakhetdinov Shamil <mcp2004 at mail.ru>:
>Hi Scott --
>
>Thank you for your sample. I have prepared mine, which I will post here in several subsequent posts as one posting limit is 20KB.
>
>By "individual changes" I mean *all* the data changes happened between data load and data saving, And I wanted to "capture" that individual data changes as soon as they happen not before .SaveChanges() call.
<<< skipped >>>
>


More information about the dba-VB mailing list