public override int SaveChanges()
        {
            this.SaveWithStoredProcedures();

            foreach (var entry in ChangeTracker.Entries().Where(e => e.State != EntityState.Unchanged))
            {
                var args = new EntityEventArgs(entry.Entity, entry.State);

                OnSavingChanges(args);
            }

            ValidateModifiedProperties();
            ValidateDirtyEntries();

            return(base.SaveChanges());
        }
        protected void OnSavingChanges(EntityEventArgs e)
        {
            var handler = SavingChanges;

            if (handler != null)
            {
                handler(this, e);
            }

            if (e.Cancel == true)
            {
                if (e.State == EntityState.Added)
                {
                    Entry(e.Entity).State = EntityState.Detached;
                }
                else
                {
                    Entry(e.Entity).State = EntityState.Unchanged;
                }
            }
        }