【发布时间】:2021-10-30 20:26:48
【问题描述】:
所需流量:
- HTTP 请求将数据插入到 Azure 存储中的表中。目前使用邮递员和本地主机。注意:这运行成功,这是我正在努力的第 2 步。
- 当数据行作为数据类型 String 存储在此处的表 (tablename = Test) 中时,我想使用控制台应用程序查询数据。
对于我的两个问题,还请查看我在代码中的注释。
Q1) 当我只在模拟器中本地运行它以连接到我的本地表时, storageConnectionString 应该是什么?
Q2) 我现在如何使用 LINQ 查询表中的所有内容(例如第 15 行)并将其存储在变量中,然后将其打印到控制台窗口?
using System;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Table;
namespace demo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Table storage sample");
var storageConnectionString = "??"; // What should storageConnectionString be when I'm only running this locally in the emulator?
var tableName = "Test";
CloudStorageAccount storageAccount;
storageAccount = CloudStorageAccount.Parse(storageConnectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());
CloudTable table = tableClient.GetTableReference(tableName);
}
}
//How can I now query all the content in the table or for example row 15 using LINQ and store it in an variable, and print it to console window?
}
POCO
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Table;
namespace LokalTesting.TableEntities
{
public class Test: TableEntity
{
public Test()
{
}
public Test(string NameId)
{
PartitionKey = NameId;
RowKey = NameId;
}
public string NameId { get; set; }
public string Status { get; set; }
public string RoutingId { get; set; }
期望的输出:
-All rows where NameId = Jon
【问题讨论】:
-
请编辑您的问题并包括 1) 您用于模拟存储表实体的任何 POCO 模型的代码和 2) 您希望通过查询检索的示例数据。
-
嗨,我现在已经更新了 POCO 和所需的输出数据。
标签: c# linq azure-functions azure-table-storage azure-tablequery