SaveChanges entity framework 6 error with two entities

0

I'm trying to save an entity Note from the controller -> servicio -> repository and it gives error of DbEntityValidationException and I paint it by screen but then I am saving the statistics of the web and when I tried to do the SaveChanges it jumps again the DbEntityValidationException but of the entity Note, how can it be?

The two call the same code.

the two call from their corresponding service.

Controller -> Servicio -> Repository (Notas)
ControllerBase -> Servicio -> Repository (Estadisticas)

_EstadisticasRepository.Add(item);
Save();




 private void Save()
        {
            _unitOfWork.Commit();
        }



 public virtual void Add(T entity)
        {
            dbset.Add(entity);
        }



 public virtual void Commit()
        {
            try
            {
                base.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                // Exception raise =  dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                            validationErrors.Entry.Entity.ToString(),
                            validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        errorMessage += message;
                        //raise = new InvalidOperationException(message, raise);
                    }
                }
                throw new Exception(errorMessage, dbEx);
                //throw raise;
            }

        }

Error Log:

  

StackTrace: in   System.Data.Entity.Internal.InternalContext.SaveChanges () in   System.Data.Entity.Internal.LazyInternalContext.SaveChanges () in   System.Data.Entity.DbContext.SaveChanges () in   AscarizWeb.Data.Models.WebCodeEntities.Commit () in   C: \ Users \ rodrigo.ascariz \ TFSWebProject \ WebAssembly \ Main \ AscarizWeb.Data \ Models \ WebCodeEntities.cs: line   25 InnerException: NULL ExceptionMessage: Validation error for   one or several entities. See the 'EntityValidationErrors' property for   get more details.

    
asked by ascariz 14.07.2017 в 14:36
source

0 answers