I am using the Generic Repository/Unit of work code used on the Microsoft Contoso University sample:

<http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application>

And it works fine (it saves, retrieves, updates, delete etc) until there is an error at the database level. In particular, I tried to make an insert in which one of the fields was too short for the text that was passed to it. Of course it failed. The error is trapped in a try/catch block, and then an error message is displayed. Problem is, after that, even when entering new information to the form (this is, valid, as in with the right text size), the SaveChanges method keeps failing, with exactly the same error (field XYZ must be a string or array type with a maximum length of '999'). It only stops until I stop the debug and I restart the execution of the ASP.NET project

For clarity purposes, this is the code I have:
(GenericRepository.cs)

```
public class GenericRepository<TEntity> where TEntity : class
{
    internal DBORAContext context;
    internal DbSet<TEntity> dbSet;

    public GenericRepository(DBORAContext context)
    {
        this.context = context;
        this.dbSet = context.Set<TEntity>();
    }

    public virtual IEnumerable<TEntity> Get(
        Expression<Func<TEntity, bool>> filter = null,
        Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
        string includeProperties = "")
    {

        IQueryable<TEntity> query = dbSet;

        if (filter != null)
        {
            query = query.Where(filter);
        }

        foreach (var includeProperty in includeProperties.Split
            (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
        {
            query = query.Include(includeProperty);
        }

        if (orderBy != null)
        {
            return orderBy(query).ToList();
        }
        else
        {
            return query.ToList();
        }
    }

    public virtual TEntity GetByID(object id)
    {
        return dbSet.Find(id);
    }

    public virtual void Insert(TEntity entity)
    {
        dbSet.Add(entity);
    }

    public virtual void Delete(object id)
    {
        TEntity entityToDelete = dbSet.Find(id);
        Delete(entityToDelete);
    }

    public virtual void Delete(TEntity entityToDelete)
    {
        if (context.Entry(entityToDelete).State == EntityState.Detached)
        {
            dbSet.Attach(entityToDelete);
        }
        dbSet.Remove(entityToDelete);
    }

    public virtual void Update(TEntity entityToUpdate)
    {
        dbSet.Attach(entityToUpdate);
        context.Entry(entityToUpdate).State = EntityState.Modified;
    }                
}

```

(UnitOfWork.cs)

```
public class UnitOfWork : IDisposable 
    {
        private DBORAContext context = new DBORAContext();        
        private GenericRepository<Activity> activityRepository;        
        public GenericRepository<Activity> ActivityRepository
        {
            get
            {

                if (this.activityRepository == null)
                {
                    this.activityRepository = new GenericRepository<Activity>(context);
                }
                return activityRepository;
            }
        }        

        public void Save()
        {                            
            context.SaveChanges();
        }                

        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        } 
    }

```

And this is the class that calls the repository for this particular object (Activity.cs)

```
public class Activity
    {
        private static readonly UnitOfWork unitOfWork = new UnitOfWork();                

        public static POCO.Activity Get(Guid activityId)
        {
            try
            {
                var thisActivity = unitOfWork.ActivityRepository.Get(a => a.ACTIVITYID == activityId).FirstOrDefault();

                if (null != thisActivity)
                {
                    return thisActivity;
                }
                return null;
            }
            catch (Exception ex)
            {                
                new Logger(ex.Message);
                return null;
            }            
        }

        public static POCO.Activity Add(POCO.Activity activityToInsert)
        {
            try
            {
                unitOfWork.ActivityRepository.Insert(activityToInsert);
                unitOfWork.Save();
                return activityToInsert;
            }            
            catch (Exception ex)
            {
                //log.Error("Add activity error", ex);
                new Logger(ex.Message);
                throw;
            }
        }

        public static bool Update(POCO.Activity activityToUpdate)
        {
            try
            {
                unitOfWork.ActivityRepository.Update(activityToUpdate);
                unitOfWork.Save();
                return true;
            }            
            catch (Exception ex)
            {
                //log.Error("update activity error", ex);
                new Logger(ex.Message);
                throw;
            }
        }     

        public static bool Delete(POCO.Activity activityToDelete)
        {
            try
            {
                unitOfWork.ActivityRepository.Delete(activityToDelete);
                unitOfWork.Save();
                return true;
            }            
            catch (Exception ex)
            {                
                new Logger(ex.Message);
                throw;
            }
        }
    }

```

I'm using EF 4.3 on a Oracle database. Please help.