Пример #1
0
        public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext <DbDataReader> interceptionContext)
        {
            // just for update and delete commands
            if (command.CommandText.StartsWith("insert", StringComparison.InvariantCultureIgnoreCase))
            {
                var context = interceptionContext.DbContexts.First();
                var entries = context.ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();

                var auditor = new DgplsEFAuditor(MyEventHandler);
                foreach (var entry in entries)
                {
                    auditor.ApplyAuditLog(context, entry);
                }
            }
        }
Пример #2
0
        public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext <int> interceptionContext)
        {
            // just for update and delete commands
            if (command.CommandText.StartsWith("update", StringComparison.InvariantCultureIgnoreCase) ||
                command.CommandText.StartsWith("delete", StringComparison.InvariantCultureIgnoreCase))
            {
                var context = interceptionContext.DbContexts.First();
                var entries = context.ChangeTracker.Entries().Where(
                    e => e.State == EntityState.Deleted || e.State == EntityState.Modified).ToList();


                var auditor = new DgplsEFAuditor(MyEventHandler);
                foreach (var entry in entries)
                {
                    auditor.ApplyAuditLog(context, entry);
                }
            }
        }