我正在编写下面的代码来从Azure表中检索所有实体.但我有点坚持通过实体解析员代表.我在
MSDN上找不到太多参考.
有人可以指出,如何在下面的代码中使用EntityResover?
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; } }
解决方法
Here is a nice article深入描述了表存储.它还包括EntityResolver的几个示例.
理想的是拥有一个产生所需结果的通用解析器.然后,您可以将其包含在通话中.我将在这里引用所提供文章中的一个例子:
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);
阅读完整的文章,以更好地了解解析器的交易.
原文地址:https://www.jb51.cc/csharp/99973.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。