How to use EntityResolver with Azure Storage?

I am writing below code to retrieve all objects from an Azure table. But I’m kind of stuck in the matter of delegating entity resolution. I could not find many links on MSDN .

Can anyone point out how to use EntityResover in the below code?

public class ATSHelper<T> where T : ITableEntity, new() { CloudStorageAccount storageAccount; public ATSHelper(CloudStorageAccount storageAccount) { this.storageAccount = storageAccount; } public async Task<IEnumerable<T>> FetchAllEntities(string tableName) { List<T> allEntities = new List<T>(); CloudTable table = storageAccount.CreateCloudTableClient().GetTableReference(tableName); TableContinuationToken contToken = new TableContinuationToken(); TableQuery query = new TableQuery(); CancellationToken cancelToken = new CancellationToken(); do { var qryResp = await table.ExecuteQuerySegmentedAsync<T>(query, ???? EntityResolver ???? ,contToken, cancelToken); contToken = qryResp.ContinuationToken; allEntities.AddRange(qryResp.Results); } while (contToken != null); return allEntities; } } 
+5
source share
1 answer

Here is a good article describing storing tables in depth. It also includes a couple of samples for EntityResolver.

It would be ideal to have one Generic Resolver that will give the desired result. Then you can include it in your call. I will just give one example from the provided article:

 EntityResolver<ShapeEntity> shapeResolver = (pk, rk, ts, props, etag) => { ShapeEntity resolvedEntity = null; string shapeType = props["ShapeType"].StringValue; if (shapeType == "Rectangle") { resolvedEntity = new RectangleEntity(); } else if (shapeType == "Ellipse") { resolvedEntity = new EllipseEntity(); } else if (shapeType == "Line") { resolvedEntity = new LineEntity(); } // Potentially throw here if an unknown shape is detected resolvedEntity.PartitionKey = pk; resolvedEntity.RowKey = rk; resolvedEntity.Timestamp = ts; resolvedEntity.ETag = etag; resolvedEntity.ReadEntity(props, null); return resolvedEntity; }; currentSegment = await drawingTable.ExecuteQuerySegmentedAsync(drawingQuery, shapeResolver, currentSegment != null ? currentSegment.ContinuationToken : null); 

Read the full article to better understand the deal with converters.

+8
source

Source: https://habr.com/ru/post/1203818/


All Articles