Exemple #1
0
 protected internal DocumentPartition(CloudStorageAccount storageAccount, string tableName, string partitionKey, Func <T, string> rowKey, IDocumentSerializer serializer)
 {
     TableName    = tableName ?? DocumentPartition.GetDefaultTableName <T>();
     PartitionKey = partitionKey ?? TablePartition.GetDefaultPartitionKey <T>();
     repository   = new DocumentRepository <T>(storageAccount,
                                               TableName,
                                               _ => PartitionKey,
                                               rowKey ?? RowKeyAttribute.CreateCompiledAccessor <T>(),
                                               serializer);
 }
Exemple #2
0
        protected internal TablePartition(CloudStorageAccount storageAccount, string tableName, string partitionKey, Expression <Func <T, string> > rowKey)
        {
            TableName = tableName ?? TablePartition.GetDefaultTableName <T>();
            partitionKey ??= TablePartition.GetDefaultPartitionKey <T>();
            PartitionKey = partitionKey;

            repository = new TableRepository <T>(storageAccount,
                                                 TableName,
                                                 _ => partitionKey,
                                                 rowKey ?? RowKeyAttribute.CreateAccessor <T>());
        }
Exemple #3
0
        public async Task CanFilterByColumn()
        {
            var account = CloudStorageAccount.DevelopmentStorageAccount;

            await LoadBooksAsync(TableRepository.Create <Book>(account, nameof(CanFilterByColumn), x => x.Author, x => x.ISBN));

            var repo = TablePartition.Create <Book>(account, nameof(CanFilterByRowKey), "Rick Riordan", x => x.ISBN);

            // Get specific set of books from one particular publisher/country combination
            // in this case, 978-[English-speaking country, 1][Disney Editions, 4231]
            // See https://en.wikipedia.org/wiki/List_of_group-1_ISBN_publisher_codes
            var query = from book in repo.CreateQuery()
                        where book.Pages >= 1000 && book.Pages <= 1500
                        select new { book.ISBN, book.Title };

            var result = await query.AsAsyncEnumerable().ToListAsync();

            Assert.Single(result);
        }
Exemple #4
0
        public async Task CanProjectPartition()
        {
            var account = CloudStorageAccount.DevelopmentStorageAccount;

            // Load with author + isbn as keys
            await LoadBooksAsync(TableRepository.Create <Book>(account, nameof(CanProjectPartition), x => x.Author, x => x.ISBN));

            // Query single author by scoping to partition key
            var repo = TablePartition.Create <Book>(account, nameof(CanProjectPartition), "Rick Riordan", x => x.ISBN);

            var hasResults = false;

            await foreach (var info in from book in repo.CreateQuery()
                           where book.Format == BookFormat.Hardback && book.IsPublished
                           select new { book.ISBN, book.Title })
            {
                hasResults = true;
                Assert.NotNull(info.ISBN);
                Assert.NotNull(info.Title);
            }

            Assert.True(hasResults);
        }