Example #1
0
        public virtual string SaveChanges()
        {
            string ret = "";

            db.SaveChanges();
            return(ret);
        }
Example #2
0
        public virtual string SaveChanges()
        {
            string ret = "";

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex0)
            {
                foreach (var eve in ex0.EntityValidationErrors)
                {
                    ret += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        ret += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception inner = ex;
                while (inner.InnerException != null)
                {
                    inner = inner.InnerException;
                }
                ret = inner.Message;
            }
            return(ret);
        }