/// <summary> /// Generic method for getting all the rows in the table which corresponds with the query string. /// </summary> /// <typeparam name="TOuput">Object type of the output data.</typeparam> /// <param name="strQuery">A string object which contains the query condition for the search.</param> /// <param name="objValues">An array of object values which will be referenced during the search.</param> /// <param name="pageNo">Page number the user is currently viewing.</param> /// <param name="pageSize">Total number of rows per page.</param> /// <param name="orderBy">Column to order by the rows.</param> /// <returns>List of the output object type.</returns> public List <TOuput> GetAll <TOuput>(String strQuery, object[] objValues, Int32 pageNo, Int32 pageSize, String orderBy) { List <TOuput> result = null; IQueryable <TObject> entities; if (string.IsNullOrWhiteSpace(strQuery)) { entities = _context.Set <TObject>(); } else { entities = _context.Set <TObject>().Where(strQuery, objValues); } if (entities != null && pageNo > 0) { var pagedRes = entities.OrderBy(orderBy).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList(); result = MappingConfiguration.MapObjectsList <TObject, TOuput>(pagedRes); } else { result = MappingConfiguration.MapObjectsList <TObject, TOuput>(entities.ToList()); } return(result); }
/// <summary> /// Generic method for getting all the rows in the table. /// </summary> /// <typeparam name="TOuput">Object type of the output data.</typeparam> /// <returns>List of the output object type.</returns> public List <TOuput> GetAll <TOuput>() { var entity = _context.Set <TObject>(); var result = MappingConfiguration.MapObjectsList <TObject, TOuput>(entity.ToList()); return(result); }
/// <summary> /// Generic method for getting all the rows in the table which will match the filter. /// </summary> /// <typeparam name="TInput">Object type of the input data.</typeparam> /// <typeparam name="TOuput">Object type of the output data.</typeparam> /// <param name="filter">A lambda expression that will filter the list.</param> /// <returns>List of the output object type.</returns> public List <TOuput> GetAll <TInput, TOuput>(Expression <Func <TInput, bool> > filter) { var where = AutoMapperExtensions.GetMappedSelector <TInput, TObject>(filter); var entity = _context.Set <TObject>().Where(where); var result = MappingConfiguration.MapObjectsList <TObject, TOuput>(entity.ToList()); return(result); }
/// <summary> /// Generic asynchronous method for getting all the rows in the table. /// </summary> /// <typeparam name="TOuput">Object type of the output data.</typeparam> /// <returns>List of the output object type.</returns> public async Task <List <TOuput> > GetAllAsync <TOuput>() { var entity = await _context.Set <TObject>().ToListAsync(); var result = MappingConfiguration.MapObjectsList <TObject, TOuput>(entity.ToList()); return(result); }
/// <summary> /// Generic method that will insert multiple rows in the table. /// </summary> /// <typeparam name="TInput">Object type of the input data.</typeparam> /// <typeparam name="TOuput">Object type of the output data.</typeparam> /// <param name="input">List of input object that will be inserted in the table.</param> /// <returns>List of the inserted object.</returns> public List <TOutPut> AddMultiple <TInput, TOutPut>(List <TInput> input) { var entityObjList = MappingConfiguration.MapObjectsList <TInput, TObject>(input); foreach (var addobject in entityObjList) { _context.Set <TObject>().Add(addobject); } _context.SaveChanges(); var result = MappingConfiguration.MapObjectsList <TObject, TOutPut>(entityObjList); return(result); }