public IList <Search> GetItems(SearchDependencies?dependencies = null) { using (_connection = Utilities.Database.GetProfiledOpenConnection()) { var result = _connection.GetList <Search>().ToList(); if (result.Any() && dependencies != null) { if ((dependencies & SearchDependencies.Logs) == SearchDependencies.Logs) { List <SearchHistoryLog> Logs = null; var searchIds = (from s in result let searchId = s.SearchId select searchId).ToList(); if (searchIds.Any()) { Logs = _searchHistoryLogRepository.GetItems(searchIds).ToList(); } if (Logs != null && Logs.Any()) { foreach (var search in result) { search.Logs = Logs.FindAll(s => s.SearchId == search.SearchId).ToList(); search.LastLog = search.Logs.OrderByDescending(l => l.SearchDate).FirstOrDefault(); } } } } return(result.ToList()); } }