Ejemplo n.º 1
0
 /// <summary>
 /// Get all the matching record from the database. Inlcude Supported
 /// </summary>
 /// <returns></returns>
 protected IQueryable <Entity> GetAllNew(Expression <Func <Entity, Boolean> > predicate)
 {
     try
     {
         if (_includes.Count == 0)
         {
             return(GetObjectSet().Where(predicate).ForEach(item => item.DecryptRecords <Entity>()));
         }
         else
         {
             DbQuery <Entity> entityQuery = GetObjectSet().Include(_includes.Dequeue());
             while (_includes.Count > 0)
             {
                 entityQuery = entityQuery.Include(_includes.Dequeue());
             }
             return(entityQuery.Where(predicate).ForEach(item => item.DecryptRecords <Entity>()));
         }
     }
     catch (ArgumentException e)
     {
         throw new ExceptionDataError(e, ExceptionBase.GetRefId());
     }
     catch (Exception e)
     {
         throw new ExceptionCritical(e, ExceptionBase.GetRefId());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// DB save method. This method is called internally.
        /// But if you want to update multiple tables in a same call then you suppose to handle it manually.
        /// </summary>
        /// <returns>Save status. The number of records updated.</returns>
        /// <exception cref="ExceptionDataError"></exception>
        /// <exception cref="ExceptionRepeatable"></exception>
        /// <exception cref="ExceptionNoneRepeatable"></exception>
        /// <exception cref="ExceptionCritical"></exception>
        public int SaveChanges()
        {
            try
            {
                int i = _context.SaveChanges();
                return(i);
            }
            catch (DbEntityValidationException dbEx)
            {
                StringBuilder s = new StringBuilder("Validation Error: ");
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        s.AppendFormat("\r\nClass: {0}, Property: {1}, Error: {2} ",
                                       validationErrors.Entry.Entity.GetType().FullName,
                                       validationError.PropertyName,
                                       validationError.ErrorMessage);
                    }
                }

                throw new ExceptionDataError(new Exception(s.ToString()), ExceptionBase.GetRefId());
            }
            catch (ArgumentException e)
            {
                throw new ExceptionDataError(e, ExceptionBase.GetRefId());
            }
            catch (System.Data.Entity.Core.OptimisticConcurrencyException e)
            {
                throw new ExceptionRepeatable(e);
            }
            catch (System.Data.Entity.Core.UpdateException e)
            {
                throw new ExceptionDataError(e, ExceptionBase.GetRefId());
            }
            catch (SqlException e)
            {
                throw new ExceptionNoneRepeatable(e, ExceptionBase.GetRefId());
            }
            catch (Exception e)
            {
                throw new ExceptionCritical(e, ExceptionCritical.GetRefId());
            }
        }
Ejemplo n.º 3
0
 protected IEnumerable <Entity> GetAllFromCache(Expression <Func <Entity, Boolean> > predicate
                                                , CachePolicy cachePolicy   = null
                                                , IEnumerable <string> tags = null)
 {
     try
     {
         if (_includes.Count == 0)
         {
             if (cachePolicy != null)
             {
                 return(GetObjectSet().Where(predicate).FromCache(cachePolicy, tags).ForEach(item => item.DecryptRecords <Entity>()));
             }
             else
             {
                 return(GetObjectSet().Where(predicate).FromCache().ForEach(item => item.DecryptRecords <Entity>()));
             }
         }
         else
         {
             DbQuery <Entity> entityQuery = GetObjectSet().Include(_includes.Dequeue());
             while (_includes.Count > 0)
             {
                 entityQuery = entityQuery.Include(_includes.Dequeue());
             }
             if (cachePolicy != null)
             {
                 return(entityQuery.Where(predicate).FromCache(cachePolicy, tags).ForEach(item => item.DecryptRecords <Entity>()));
             }
             else
             {
                 return(entityQuery.Where(predicate).FromCache().ForEach(item => item.DecryptRecords <Entity>()));
             }
         }
     }
     catch (ArgumentException e)
     {
         throw new ExceptionDataError(e, ExceptionBase.GetRefId());
     }
     catch (Exception e)
     {
         throw new ExceptionCritical(e, ExceptionBase.GetRefId());
     }
 }