예제 #1
0
        private void SetExcepton(System.Data.Entity.Validation.DbEntityValidationException ex)
        {
            foreach (System.Data.Entity.Validation.DbEntityValidationResult vr in ex.EntityValidationErrors)
            {
                var dte = new DbTransException();
                dte.Type  = "DbEntityValidationException";
                dte.Lable = vr.Entry.Entity.ToString();

                foreach (System.Data.Entity.Validation.DbValidationError ve in vr.ValidationErrors)
                {
                    dte.Exception.Add(new DbTransExceptionError
                    {
                        Message   = ve.ErrorMessage,
                        Reference = ve.PropertyName
                    });
                }
                Exception.Add(dte);
            }
        }
예제 #2
0
        public bool Create(T Entity)
        {
            try
            {
                db.Set <T>().Add(Entity);
                db.SaveChanges();
                return(true);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                SetExcepton(ex);
                return(false);
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
            {
                // TODO : Need to re-evaluate, How clectively handel exceptions
                // Related to Entity
                var dte = new DbTransException();
                //dte.Type = "OracleException";
                dte.Lable = ""; //ex.Entries.;

                dte.Exception.Add(new DbTransExceptionError
                {
                    Message   = ex.InnerException.InnerException.Message,
                    Reference = ""
                });

                Exception.Add(dte);

                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
                //return false;
            }
        }