예제 #1
0
        public virtual bool Insert(T entity)
        {
            bool result;

            try
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                Table.Add(entity);
                Context.SaveChanges();
                result = true;
            }
            catch (DbEntityValidationException dbEx)
            {
                var msg = string.Empty;

                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        msg += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine;
                    }
                }

                var fail = new Exception(msg, dbEx);
                //throw fail;
                result = false;
            }
            return(result);
        }
예제 #2
0
 public void Save()
 {
     Context.SaveChanges();
 }