public RepositoryResultList <T> QueryByESql(string esql, PagingCriteria paging) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { this.RefreshData(); var data = ctx.Set <T>().SqlQuery(esql); int totalRecords = data.Count(); result.Entities = data.AsQueryable() .OrderBy(paging.SortBy + " " + paging.SortDirection) .Skip((paging.PageNumber - 1) * paging.PageSize) .Take(paging.PageSize) .AsEnumerable(); result.PagedMetadata = new PagedMetadata(totalRecords, paging.PageSize, paging.PageNumber); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser /// method or a simple lambda expression /// </summary> /// <param name="filter">the Expression to use to filter objects from the data store</param> /// <param name="paging">PagingCriteria for the result list</param> /// <param name="includes">a params string array of property names that will be included in the resulting object graph for each item</param> /// <returns>RepositoryResultList</returns> public RepositoryResultList <T> Find(Expression <Func <T, bool> > filter, PagingCriteria paging, params string[] includes) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { var query = ctx.Set <T>().Where(t => true); foreach (string include in includes) { query = query.Include(include); } query = query.Where(filter.Compile()).AsQueryable(); int totalRecords = query.Count(); result.Entities = query.AsQueryable() .OrderBy(paging.SortBy + " " + paging.SortDirection) .Skip((paging.PageNumber - 1) * paging.PageSize) .Take(paging.PageSize) .AsEnumerable(); result.PagedMetadata = new PagedMetadata(totalRecords, paging.PageSize, paging.PageNumber); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// Gets all of T from the data store /// </summary> /// <param name="paging">pagingcriteria to determine which page of T to return</param> /// <param name="includes">a parameter string array of property names to return in each item of the entity object graph</param> /// <returns>RepositoryResultList</returns> public RepositoryResultList <T> GetAll(PagingCriteria paging, params string[] includes) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { var data = ctx.Set <T>().Where(t => true); int totalRecords = data.Count(); foreach (string include in includes) { data = (IQueryable <T>)data.Include(include); } result.Entities = data.AsQueryable() .OrderBy(paging.SortBy + " " + paging.SortDirection) .Skip((paging.PageNumber - 1) * paging.PageSize) .Take(paging.PageSize) .AsEnumerable(); result.PagedMetadata = new PagedMetadata(totalRecords, paging.PageSize, paging.PageNumber); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser /// method or a simple lambda expression /// </summary> /// <param name="filter">the Expression to use to filter objects from the data store</param> /// <returns>RepositoryResultList</returns> public RepositoryResultList <T> Find(System.Linq.Expressions.Expression <Func <T, bool> > filter) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { result.Entities = ctx.Set <T>().Where(filter.Compile()); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// Gets All items of Type T from the data store /// </summary> /// <returns>IEnumerable of the specified Type/></returns> public RepositoryResultList <T> GetAll() { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { result.Entities = ctx.Set <T>().AsEnumerable(); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// 获得存储过程结果集 /// </summary> /// <param name="storedProc"></param> /// <param name="parm"></param> /// <returns></returns> //public ResultsList CallStoredProc(StoredProc<T> storedProc, T parm) //{ // //ResultsList results = ctx.CallStoredProc<T>(storedProc, parm); // //return results; // return null; //} public RepositoryResultList <T> QueryByESql(string esql) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { this.RefreshData(); result.Entities = ctx.Set <T>().SqlQuery(esql).ToList(); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser /// method or a simple lambda expression /// </summary> /// <param name="filter">the Expression to use to filter objects from the data store</param> /// <param name="includes">a params string array of property names that will be included in the resulting object graph for each item</param> /// <returns>RepositoryResultList</returns> public RepositoryResultList <T> Find(System.Linq.Expressions.Expression <Func <T, bool> > filter, params string[] includes) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { var query = ctx.Set <T>().Where(t => true); foreach (string include in includes) { query = query.Include(include); } result.Entities = query.Where(filter.Compile()); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// Gets all of T from the data store /// </summary> /// <param name="includes">A list of property names to return in the object graph</param> /// <returns>RepositoryReslutList</returns> public RepositoryResultList <T> GetAll(params string[] includes) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { var query = ctx.Set <T>().Where(t => true); foreach (string include in includes) { query = (IQueryable <T>)query.Include(include); } result.Entities = query.AsEnumerable(); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }