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

Salakhetdinov Shamil mcp2004 at mail.ru
Tue Apr 16 20:39:26 CDT 2013


 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.


Вторник, 16 апреля 2013, 9:16 -04:00 от Scott Marcus <scott.marcus at tsstech.com>:
>I guess I'm not sure what you mean by individual changes. SaveChanges should happen at your whim and whether it is to one record or many records is your call. Perhaps there is a misunderstanding since I am using an MVC repository method in ASP.NET. I just thought entity framework behaves the same regardless the environment.
>
>Here is an example...
>
>    public class MyModelRepository : IMyModelRepository
>    {
>        private EFDbContext context = new EFDbContext();
>
>        public IQueryable<MyModel> MyModels
>        {
>            get { return context.MyModels; }
>        }
>
>        public void Save(MyModel someRecord, int loginID, string changesMade = "Record Created")
>        {
>            DateTime changesMadeDateAndTime = DateTime.Now;
>            AuditModel auditRecord = new AuditModel
>            {
>                WhoDoneIt = loginID,
>                WhatDidTheyDo = changesMade,
>                WhenDidTheyDoIt = changesMadeDateAndTime
>            };
>            context.AuditRecordModels.Add(auditRecord);
>
>           // if you wanted, you could add more records and change more records before you call SaveChanges
>           // you would probably not do it in this function but in another overloaded function
>           // that handles multiple record changes
>
>            context.SaveChanges(); //saves the changes to someRecord and adds the auditRecord all in one transaction
>        }
>
>        public void Delete(MyModel someRecord, int loginID)
>        {
>            DateTime deletedDateAndTime = DateTime.Now;
>            AuditModel auditRecord = new AuditModel
>            {
>                WhoDoneIt = loginID,
>                WhatDidTheyDo = "Deleted MyModel Record: " + someRecord.RecordID,
>                WhenDidTheyDoIt = deletedDateAndTime
>            };
>            context.AuditRecordModels.Add(auditRecord);
>            context.MyModels.Remove(someRecord);
>            context.SaveChanges(); //now perform the work that adds the audit record and removes someRecord all in one transaction
>        }
>    }
>
>
>Scott

<<< skipped >>>


More information about the dba-VB mailing list