public IEnumerable <string> SearchIds(FilterFormDto <TFilter> form) { string entityName = typeof(TEntity).Name; Stopwatch sw = new Stopwatch(); sw.Start(); var dbSet = _dataService.GetDbSet <TEntity>(); var query = ApplySearchForm(dbSet, form); query = ApplyRestrictions(query); Log.Information("{entityName}.SearchIds (Apply search parameters): {ElapsedMilliseconds}ms", entityName, sw.ElapsedMilliseconds); sw.Restart(); var ids = query.Select(e => e.Id).ToList(); Log.Information("{entityName}.SearchIds (Load from DB): {ElapsedMilliseconds}ms", entityName, sw.ElapsedMilliseconds); var result = ids.Select(x => x.ToString()).ToList(); return(result); }
public IActionResult SearchIds([FromBody] FilterFormDto <TFilter> form) { try { var result = service.SearchIds(form); return(Ok(result)); } catch (UnauthorizedAccessException) { return(Unauthorized()); } catch (Exception ex) { Log.Error(ex, $"Failed to Load IDs of {typeof(TEntity).Name}"); return(StatusCode(500, ex.Message)); } }
public SearchResult <TDto> Search(FilterFormDto <TFilter> form) { string entityName = typeof(TEntity).Name; Stopwatch sw = new Stopwatch(); sw.Start(); var dbSet = _dataService.GetDbSet <TEntity>(); var query = ApplySearchForm(dbSet, form); query = ApplyRestrictions(query); Log.Information("{entityName}.Search (Apply search parameters): {ElapsedMilliseconds}ms", entityName, sw.ElapsedMilliseconds); sw.Restart(); if (form.Take == 0) { form.Take = 1000; } var totalCount = query.Count(); var entities = query.Skip(form.Skip) .Take(form.Take).ToList(); Log.Information("{entityName}.Search (Load from DB): {ElapsedMilliseconds}ms", entityName, sw.ElapsedMilliseconds); sw.Restart(); var a = new SearchResult <TDto> { TotalCount = totalCount, Items = entities.Select(entity => MapFromEntityToDto(entity)).ToList() }; Log.Information("{entityName}.Search (Convert to DTO): {ElapsedMilliseconds}ms", entityName, sw.ElapsedMilliseconds); sw.Restart(); a.Items = FillLookupNames(a.Items).ToList(); Log.Information("{entityName}.Search (Fill lookups): {ElapsedMilliseconds}ms", entityName, sw.ElapsedMilliseconds); return(a); }
public abstract IQueryable <TEntity> ApplySearchForm(IQueryable <TEntity> query, FilterFormDto <TFilter> searchForm, List <string> columns = null);