【问题标题】:How to read Azure table all rows in table entity如何读取表实体中的 Azure 表所有行
【发布时间】:2022-01-22 23:50:49
【问题描述】:

我有 Azure 表实体,其中有带有分区键、行键、Etag 和属性的 queryResult。我正在尝试阅读属性包含我的表格列。但是我在使用 LINQ 读取属性或尝试循环属性时遇到问题,我必须再次循环属性,因为它包含我的表列...引用了一些告诉使用 table.ExecuteQuery(query);

但我得到的响应包含 4 个值,属性包含我的实际列数据....任何帮助都非常感谢。

        Public class MyEntityModel : TableEntity
        {
             MyEntityModel (){}
                MyEnityModel(string Category, string Id){
                    PartitionKey=Category;
                    RowKey= Id;
              }

              Public string leaveCount{ get;set;}
              Public string leaveReason{get;set;}
         }

    TableQuery<DynamicTableEntity> query=new 
    TableQuery<DynamicTableEntity>();
     Var result = table.ExecuteQuerySegmented(query,token)
    Var entityItems=result.Results;
    Var propsItems=entityItems.Select(x=>x Properties). ToList();

即使我提供我的实体模型来查询

    TableQuery <MyEntityModel> query = new TableQuery();

我正在获取具有分区键和 RowKey 值的数据,但属性(实体列值)为空。

【问题讨论】:

  • 请编辑您的问题并包含您的代码。
  • 感谢分享代码。您能否再编辑一次并包含实体的属性。
  • 感谢您的回复......

标签: c# azure azure-table-storage azure-tablequery


【解决方案1】:

我们可以使用 EntityPropertConverter 来获取属性详细信息,如下所示

var myAzureColumnData = EntityPropertyConverter.ConvertBack<MyEntityModel>(Properties,  new OperationContext());

这给了我列值。

我们也可以这样做

 Var result = table.ExecuteQuery(new TableQuery<MyEntityModel>());

这将创建一个具有值的对象......

【讨论】:

    猜你喜欢
    • 2011-04-10
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 2023-03-17
    • 2014-07-19
    • 2013-02-19
    相关资源
    最近更新 更多