Cybercrux

Everything is achievable through technology

Entity framework

public IEnumerable<TEntity> AllInclude<TEntity>
                          (params System.Linq.Expressions.Expression<Func<TEntity, object>>[] includeProperties) where TEntity : class
      {
          return GetAllIncluding(includeProperties).ToList();
      }
 
      public IQueryable<TEntity> GetAllIncluding<TEntity>(params Expression<Func<TEntity, object>>[] includeProperties) where TEntity : class
      {
          DbSet<TEntity> _dbSet = _submissionDbContext.Set<TEntity>();
          IQueryable<TEntity> queryable = _dbSet.AsNoTracking();
          return includeProperties.Aggregate(queryable, (current, includeProperty) => current.Include(includeProperty));
      }
 
      public Tuple<IQueryable<TEntity>, int, int> ReviewedArticlesWithAuthor<TEntity>(string searchKey, string searchOption
          , int pageNumber, int pageSize)
      {
 
          var query = "EXEC spname@SearchKey, @SearchOption, @PageNumber, @PageSize";
          var parameters = new[] {
          new SqlParameter("@SearchKey", searchKey)
              , new SqlParameter("@SearchOption", searchOption)
              , new SqlParameter("@PageNumber", pageNumber)
              , new SqlParameter("@PageSize", pageSize)
              };
 
          IQueryable<TEntity> relatedArticleList;
          int totalPages;
          int totalRows;
 
          using (var multiResultSet = _submissionDbContext.MultiResultSetSqlQuery(query, parameters))
          {
              relatedArticleList = multiResultSet.ResultSetFor<TEntity>().ToList().AsQueryable();
              totalPages = multiResultSet.ResultSetFor<int>().ToArray().FirstOrDefault();
              totalRows = multiResultSet.ResultSetFor<int>().ToArray().FirstOrDefault();
          }
 
          return new Tuple<IQueryable<TEntity>, int, int>(relatedArticleList, totalPages, totalRows);
      }