GlobalDemo.DAL.Azure.StorageRepository.GetPhotosFromTableAsync C# (CSharp) Method

GetPhotosFromTableAsync() public method

This is a partition scan. Less optimal, but not as bad as a full table scan.
public GetPhotosFromTableAsync ( string tableName, string partitionKey ) : Task>
tableName string
partitionKey string
return Task>
        public async Task<IEnumerable<PhotoModel>> GetPhotosFromTableAsync(            
            string tableName,
            string partitionKey)
        {
            
            var client = _account.CreateCloudTableClient();
            var table = client.GetTableReference(tableName);

            var ret = new List<PhotoModel>();

            TableQuery<PhotoEntity> partitionScanQuery = new TableQuery<PhotoEntity>().Where
                (TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey));

            TableContinuationToken token = null;
            // Page through the results
            do
            {
                TableQuerySegment<PhotoEntity> segment = await table.ExecuteQuerySegmentedAsync(partitionScanQuery, token);
                token = segment.ContinuationToken;
                foreach (PhotoEntity entity in segment)
                {
                    ret.Add(new PhotoModel(entity));
                }
            }
            while (token != null);

            return ret;
        }

Usage Example

        public async Task<IHttpActionResult> Get()
        {
            var cache = RedisCache.Connection.GetDatabase();
            var repo = new RedisRepository(cache);

            string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;

            var items = await repo.GetPhotosForUserAsync(owner);
            //Do this so we can get the count
            List<IPhotoModel> typedItems = new List<IPhotoModel>(items);
            
            if(typedItems.Count == 0)
            {
                //Nothing in cache... head off to storage.
                var storageRepo = new StorageRepository(SettingsHelper.LocalStorageConnectionString);
                
                var photos = await storageRepo.GetPhotosFromTableAsync( DAL.Azure.StorageConfig.TableName, owner);
                foreach (var photo in photos)
                {
                    //TODO: Find a MUCH better algorithm than
                    //      iterating every item and calling
                    //      Redis 3 times in a row for each
                    //      item.  This is PAINFUL.
                    await repo.AddPhotoToCachesAsync(photo);
                }
                items = photos;                
            }
            return Ok(items);
        }