0

Desired flow:

  1. HTTP Request to insert data into a table in azure storage. Currently using Postman and localhost. Note: This is running sucessfully and it is step 2 I'm struggeling with. <-- Azure Function
  2. When data rows is stored in a table here (tablename = Test) as datatype String, I want to query the data by using a console application. <-- Console Application (se code below)

enter image description here

Please also look at my comment in the code for my two questions.

Q1) What should storageConnectionString be when I'm only running this locally in the emulator in order to connect to my local table?

Q2) 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?

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; }

Desired output:

-All rows where NameId = Jon
4

1 回答 1

0

Q1 - 尝试"UseDevelopmentStorage=true"

Q2 -

var rows = new List<Test>();
var query = new TableQuery<Test>().Where(TableQuery.GenerateFilterCondition("<propertyName>", QueryComparisons.Equal, propertyValue));

TableContinuationToken continuationToken = null;

do
{
    var queryResult = await table.ExecuteQuerySegmentedAsync(query, continuationToken);
    rows.AddRange(queryResult);
    continuationToken = queryResult.ContinuationToken;
} while (continuationToken != null);

在这里您可以生成查询:var query = new TableQuery<Test>().Where(TableQuery.GenerateFilterCondition("NameId", QueryComparisons.Equal, "Jon"));

于 2021-09-01T11:08:57.913 回答