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

Scott Marcus tsm at zoomtown.com
Mon Apr 15 17:50:07 CDT 2013


Before calling the save changes method, add the audit record to the context and change its state to modified. Then call the save changes method.

i.e. (in c#)

Audit audit = new Audit({UserName = username, RecordID = changedRecordID});
context.Entry(audit).State = EntityState.Modified;
context.SaveChanges;

Sent from my iPad

On Apr 15, 2013, at 4:39 PM, Salakhetdinov Shamil <mcp2004 at mail.ru> wrote:

> Hi Scott --
> 
> I'm trying to audit trail *individual* changes while the rows' editions, additions, deletions are done using a DataGridView bound to a DbSet<{{EntityType}}>  of a {{CustomModel}}Container: DbContext IOW before they get saved/committed to the backend.
> 
> I have set custom events processing for the BidindingSource.ListChanged event and for the DataGridView.RowsRemoved event. They together allow me to audit trail changes on client side. But I suppose this custom audit trail solution is a bit tricky to be true - there should be a simpler one?
> 
> I can also audit trail the changes in a "batch" mode before they get saved to the backend by using .SaveChanges method of a {{CustomModel}}Container: DbContext then custom events processing of the BidindingSource.ListChanged event and of the DataGridView.RowsRemoved isn't needed. But I'd prefer to have an option to audit trail *individual* changes using simpler solution than I have currently got working.
> 
> I must note that the subject issue isn't currently needed here to be solved for any real life project - it's more a "research" kind of issue helping to learn better how bound WinForms communicate with their "model first" datasources...
> 
> Thank you.
> 
> -- Shamil
> 
> 
> Понедельник, 15 апреля 2013, 10:50 -04:00 от Scott Marcus <scott.marcus at tsstech.com>:
>> Where are you trying to perform the audit routines? Are you doing the audit changes after saving the changes to your model. Ideally, you would be making the audit records within the same savechanges context (since all changes are within the same transaction) so that any error to the savechanges does not create an audit of the changes that were rolled back.
>> 
>> -----Original Message-----
>> From:  dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Salakhetdinov Shamil
>> Sent: Monday, April 15, 2013 7:23 AM
>> To: Discussion concerning Visual Basic and related programming issues.
>> Subject: [dba-VB] CodeFirst, DataBinding and audit trailing deleted items on client side
>> 
>>  Hi All --
>> 
>> I have made a sample app here using CodeFirst ADO.NET EF approach. It works well. I just cannot currently solve one issue, namely:
>> 
>> - to audit trail items deleted in a bound DataGridView.
>> 
>> I have found how to find deleted items in a bound DbSet<{{EntityType}} list but the issue is that deleted item gets its item Id (surrogate key) zeroed, so my audit trailing can't be used to find corresponding database record.
>> 
>> Any ideas?
>> 
>> Thank you.
>> 
>> -- Shamil
>> _______________________________________________
>> dba-VB mailing list
>> dba-VB at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/dba-vb
>> http://www.databaseadvisors.com
>> 
>> 
>> NOTICE:  This electronic mail transmission is for the use of the named individual or entity to which it is directed and may contain information that is privileged or confidential.  If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of any information contained herein is prohibited.  If you have received this electronic mail transmission in error, delete it from your system without copying or forwarding it, and notify the sender of the error by replying via email or calling TSS Technologies at (513) 772-7000, so that our address record can be corrected.
>> Any information included in this email is provided on an “as is” and “where as” basis, and TSS Technologies makes no representations or warranties of any kind with respect to the completeness or accuracy of the information contained in this email.
> 
> _______________________________________________
> dba-VB mailing list
> dba-VB at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vb
> http://www.databaseadvisors.com
> 



More information about the dba-VB mailing list