Beispiel #1
0
        void LogDeleted(LOG_SYSTEM logSystem)
        {
            var addEntities = ChangeTracker.Entries()
                              .Where(p => p.State == EntityState.Deleted).ToList();

            foreach (var change in addEntities)
            {
                LOG_ROW logRow = logSystem.NewRow();
                logRow.STATUS     = change.State.ToString();
                logRow.TABLE_NAME = change.Entity.GetType().Name;

                var primaryKey = GetColumnKeyName(change);

                foreach (var prop in change.OriginalValues.PropertyNames)
                {
                    LOG_COLUMN logColumn = logRow.NewColumn();
                    logColumn.COLUMN_NAME = prop;
                    logColumn.IS_KEY      = primaryKey.Contains(prop);
                    if (change.OriginalValues[prop] != null)
                    {
                        logColumn.OLD_VALUE = change.OriginalValues[prop].ToString();
                    }
                }
            }
        }
Beispiel #2
0
        void LogModified(LOG_SYSTEM logSystem)
        {
            var modifiedEntities = ChangeTracker.Entries()
                                   .Where(p => p.State == EntityState.Modified).ToList();

            foreach (var change in modifiedEntities)
            {
                LOG_ROW logRow = logSystem.NewRow();
                logRow.STATUS     = change.State.ToString();
                logRow.TABLE_NAME = change.Entity.GetType().Name;

                var primaryKey = GetColumnKeyName(change);

                foreach (var prop in change.OriginalValues.PropertyNames)
                {
                    var iskey = primaryKey.Contains(prop);

                    var originalValue = change.OriginalValues[prop] != null ? change.OriginalValues[prop].ToString() : "";
                    var currentValue  = change.CurrentValues[prop] != null ? change.CurrentValues[prop].ToString() : "";
                    if (originalValue != currentValue | iskey)
                    {
                        LOG_COLUMN logColumn = logRow.NewColumn();
                        logColumn.COLUMN_NAME = prop;
                        logColumn.IS_KEY      = primaryKey.Contains(prop);
                        logColumn.OLD_VALUE   = originalValue;
                        logColumn.NEW_VALUE   = currentValue;
                    }
                }
            }
        }