You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/storage/tables/table-storage-design-patterns.md
+52-30Lines changed: 52 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -627,13 +627,13 @@ Consider the following points when deciding how to store log data:
627
627
628
628
## Implementation considerations
629
629
630
-
This section discusses some of the considerations to bear in mind when you implement the patterns described in the previous sections. Most of this section uses examples written in C# that use the Storage Client Library (version 4.3.0 at the time of writing).
630
+
This section discusses some of the considerations to bear in mind when you implement the patterns described in the previous sections. Most of this section uses examples written in C# that use the Storage client library (version 4.3.0 at the time of writing).
631
631
632
632
## Retrieving entities
633
633
634
-
As discussed in the section Design for querying, the most efficient query is a point query. However, in some scenarios you may need to retrieve multiple entities. This section describes some common approaches to retrieving entities using the Storage Client Library.
634
+
As discussed in the section Design for querying, the most efficient query is a point query. However, in some scenarios you may need to retrieve multiple entities. This section describes some common approaches to retrieving entities using the Storage client library.
635
635
636
-
### Executing a point query using the Storage Client Library
636
+
### Executing a point query using the Storage client library
637
637
638
638
The easiest way to execute a point query is to use the **GetEntityAsync** method as shown in the following C# code snippet that retrieves an entity with a **PartitionKey** of value "Sales" and a **RowKey** of value "212":
639
639
@@ -648,21 +648,19 @@ Notice how this example expects the entity it retrieves to be of type **Employee
648
648
You can use LINQ to retrieve multiple entities from the Table service when working with Microsoft Azure Cosmos DB Table Standard Library.
649
649
650
650
```azurecli
651
-
dotnet add package Microsoft.Azure.Cosmos.Table
651
+
dotnet add package Azure.Data.Tables
652
652
```
653
653
654
654
To make the below examples work, you'll need to include namespaces:
@@ -689,7 +687,7 @@ You should always fully test the performance of your application in such scenari
689
687
690
688
A query against the table service may return a maximum of 1,000 entities at one time and may execute for a maximum of five seconds. If the result set contains more than 1,000 entities, if the query did not complete within five seconds, or if the query crosses the partition boundary, the Table service returns a continuation token to enable the client application to request the next set of entities. For more information about how continuation tokens work, see [Query Timeout and Pagination](/rest/api/storageservices/Query-Timeout-and-Pagination).
691
689
692
-
If you are using the Table Client Library, it can automatically handle continuation tokens for you as it returns entities from the Table service. The following C# code sample using the Table Client Library automatically handles continuation tokens if the table service returns them in a response:
690
+
If you are using the Azure Tables client library, it can automatically handle continuation tokens for you as it returns entities from the Table service. The following C# code sample using the client library automatically handles continuation tokens if the table service returns them in a response:
In more advanced scenarios, you may want to store the continuation token returned from the service so that your code controls exactly when the next pages is fetched. The following example shows a basic scenario of how the token can be fetched and applied to paginated results:
718
+
719
+
```csharp
720
+
stringcontinuationToken=null;
721
+
boolmoreResultsAvailable=true;
722
+
while (moreResultsAvailable)
723
+
{
724
+
varpage=employeeTable
725
+
.Query<EmployeeEntity>()
726
+
.AsPages(continuationToken, pageSizeHint: 10)
727
+
.FirstOrDefault(); // pageSizeHint limits the number of results in a single page, so we only enumerate the first page
728
+
729
+
if (page==null)
730
+
break;
731
+
732
+
// Get the continuation token from the page
733
+
// Note: This value can be stored so that the next page query can be executed later
By using continuation tokens explicitly, you can control when your application retrieves the next segment of data. For example, if your client application enables users to page through the entities stored in a table, a user may decide not to page through all the entities retrieved by the query so your application would only use a continuation token to retrieve the next segment when the user had finished paging through all the entities in the current segment. This approach has several benefits:
@@ -727,12 +755,6 @@ By using continuation tokens explicitly, you can control when your application r
727
755
>
728
756
>
729
757
730
-
The following C# code shows how to modify the number of entities returned inside a segment:
731
-
732
-
```csharp
733
-
employees.max=50;
734
-
```
735
-
736
758
### Server-side projection
737
759
738
760
A single entity can have up to 255 properties and be up to 1 MB in size. When you query the table and retrieve entities, you may not need all the properties and can avoid transferring data unnecessarily (to help reduce latency and cost). You can use server-side projection to transfer just the properties you need. The following example retrieves just the **Email** property (along with **PartitionKey**, **RowKey**, **Timestamp**, and **ETag**) from the entities selected by the query.
@@ -752,9 +774,9 @@ Notice how the **RowKey** value is available even though it was not included in
ExceptionsthrownwhentheStorageClientLibraryexecutesanEGTtypicallyincludetheindexoftheentitythatcausedthebatchtofail. Thisishelpful when you are debugging code that uses EGTs.
779
+
ExceptionsthrownwhentheStorageclientlibraryexecutesanEGTtypicallyincludetheindexoftheentitythatcausedthebatchtofail. Thisishelpful when you are debugging code that uses EGTs.
Ifyouknowthetypeoftheentitystoredwithaspecific **RowKey** and **PartitionKey** values, thenyoucanspecifytheentitytypewhenyouretrievetheentityasshownintheprevioustwoexamplesthatretrieveentitiesoftype **EmployeeEntity**: [Executing a point query using the Storage Client Library](#executing-a-point-query-using-the-storage-client-library) and [Retrieving multiple entities using LINQ](#retrieving-multiple-entities-using-linq).
1004
+
Ifyouknowthetypeoftheentitystoredwithaspecific **RowKey** and **PartitionKey** values, thenyoucanspecifytheentitytypewhenyouretrievetheentityasshownintheprevioustwoexamplesthatretrieveentitiesoftype **EmployeeEntity**: [Executing a point query using the Storage client library](#executing-a-point-query-using-the-storage-client-library) and [Retrieving multiple entities using LINQ](#retrieving-multiple-entities-using-linq).
@@ -1031,7 +1053,7 @@ It is possible to generate a SAS token that grants access to a subset of the ent
1031
1053
Provided you are spreading your requests across multiple partitions, you can improve throughput and client responsiveness by using asynchronous or parallel queries.
1032
1054
For example, you might have two or more worker role instances accessing your tables in parallel. You could have individual worker roles responsible for particular sets of partitions, or simply have multiple worker role instances, each able to access all the partitions in a table.
1033
1055
1034
-
Within a client instance, you can improve throughput by executing storage operations asynchronously. The Storage Client Library makes it easy to write asynchronous queries and modifications. For example, you might start with the synchronous method that retrieves all the entities in a partition as shown in the following C# code:
1056
+
Within a client instance, you can improve throughput by executing storage operations asynchronously. The Storage client library makes it easy to write asynchronous queries and modifications. For example, you might start with the synchronous method that retrieves all the entities in a partition as shown in the following C# code:
0 commit comments