C# 控制台应用程序使用azure storage tableapi

C# 控制台应用程序使用azure storage tableapi,c#,httpclient,azure-table-storage,C#,Httpclient,Azure Table Storage,请提供一些使用OData?发送http请求以查询azure表存储的示例(控制台应用程序)更新 您可以在门户网站上找到您的sastoken,就像我的图片一样 您还需要更新HttpHelper文件中的x-ms-date(必需。指定请求的协调世界时(UTC)) 有关更多详细信息,您可以在github中下载代码(您可以下载我的HttpHelper文件) 使用Microsoft.Azure.Cosmos.Table; 使用Newtonsoft.Json; 使用制度; 使用System.Collect

请提供一些使用OData?发送http请求以查询azure表存储的示例(控制台应用程序)

更新

您可以在门户网站上找到您的
sastoken
,就像我的图片一样

您还需要更新
HttpHelper
文件中的
x-ms-date
(必需。指定请求的协调世界时(UTC))

有关更多详细信息,您可以在github中下载代码(您可以下载我的
HttpHelper
文件)

使用Microsoft.Azure.Cosmos.Table;
使用Newtonsoft.Json;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Security.Cryptography.X509证书;
使用System.Threading.Tasks;
使用静态ODatafilter.HttpHelper;
命名空间ODatafilter
{
班级计划
{
静态异步任务主(字符串[]args)
{
控制台.WriteLine(“Azure宇宙表样本”);
字符串baseurl=@“https://panshubeistorage.table.core.windows.net/";
字符串tbname=“People”//Console.ReadLine();
字符串sastoken=@?sv=2019-10-10&ss=***********”;
字符串筛选器=@“&$filter=PartitionKey%20eq%20'Smith“%20”;
baseurl=baseurl+tbname+“()”+sastoken+filter;
HttpResponseData=HttpHelper.GetForOData(baseurl);
字符串responseData=data.data.Replace(“.”,“”);
ODataResponse odata=JsonConvert.DeserializeObject(responseData);
foreach(odata.value中的ODatavalue m)
{
Console.WriteLine(m.PartitionKey+“”+m.PhoneNumber+“”+m.RowKey+“”+m.Email);
}
Console.WriteLine(“按任意键退出”);
Console.Read();
}
公共类ODataResponse
{
公共字符串odata_元数据{get;set;}
公共列表值{get;set;}
}
公共类价值{
公共字符串odata_类型{get;set;}
公共字符串odata_id{get;set;}
公共字符串odata_etag{get;set;}
公共字符串odata_editLink{get;set;}
公共字符串时间戳{get;set;}
公共字符串分区键{get;set;}
公共字符串行键{get;set;}
公共字符串电子邮件{get;set;}
公共字符串PhoneNumber{get;set;}
}
}
}
PRIVIOUS

您可以使用LinQ像支持的文档一样进行查询

static async Task Main(字符串[]args)
{
控制台.WriteLine(“Azure宇宙表样本”);
Console.WriteLine(“通过过滤器查询数据”);
CloudTable=GetTable();
控制台。写线(“请输入分区键:”);
string PartitionKey=Console.ReadLine();
控制台。写线(“请输入行键:”);
字符串RowKey=Console.ReadLine();
//质疑
IQueryable linqQuery=table.CreateQuery()
.Where(x=>x.PartitionKey==PartitionKey&&x.RowKey==RowKey)
.Select(x=>newcustomerEntity(){PartitionKey=x.PartitionKey,RowKey=x.RowKey,Email=x.Email,PhoneNumber=x.PhoneNumber});
var list=linqQuery.ToList();
foreach(列表中的客户属性m)
{
Console.WriteLine(m.PartitionKey+“”+m.PhoneNumber+“”+m.RowKey+“”+m.Email);
}
Console.WriteLine();
Console.WriteLine(“按任意键退出”);
Console.Read();
}
公共静态CloudTable GetTable(){
CloudStorageAccount=CloudStorageAccount.Parse(“DefaultEndpointsProtocol=https;AccountName=***x=core.windows.net”);
CloudTableClient tableClient=account.CreateCloudTableClient();
CloudTable=tableClient.GetTableReference(“人”);
返回表;
}

更新

您可以在门户网站上找到您的
sastoken
,就像我的图片一样

您还需要更新
HttpHelper
文件中的
x-ms-date
(必需。指定请求的协调世界时(UTC))

有关更多详细信息,您可以在github中下载代码(您可以下载我的
HttpHelper
文件)

使用Microsoft.Azure.Cosmos.Table;
使用Newtonsoft.Json;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Security.Cryptography.X509证书;
使用System.Threading.Tasks;
使用静态ODatafilter.HttpHelper;
命名空间ODatafilter
{
班级计划
{
静态异步任务主(字符串[]args)
{
控制台.WriteLine(“Azure宇宙表样本”);
字符串baseurl=@“https://panshubeistorage.table.core.windows.net/";
字符串tbname=“People”//Console.ReadLine();
字符串sastoken=@?sv=2019-10-10&ss=***********”;
字符串筛选器=@“&$filter=PartitionKey%20eq%20'Smith“%20”;
baseurl=baseurl+tbname+“()”+sastoken+filter;
HttpResponseData=HttpHelper.GetForOData(baseurl);
字符串responseData=data.data.Replace(“.”,“”);
ODataResponse odata=JsonConvert.DeserializeObject(responseData);
foreach(odata.value中的ODatavalue m)
{
Console.WriteLine(m.PartitionKey+“”+m.PhoneNumber+“”+m.RowKey+“”+m.Email);
}
Console.WriteLine(“按任意键退出”);
Console.Read();
}
公共类ODataResponse
{
公共字符串odata_元数据{get;set;}
公共列表值{get;set;}
}
公共类价值{
公共字符串odata_类型{get;set;}
公共字符串odata_id{get;set;}
公共字符串odata_etag{get;set;}
公共字符串odata
using Microsoft.Azure.Cosmos.Table;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using static ODatafilter.HttpHelper;

namespace ODatafilter
{
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("Azure Cosmos Table Samples");
            string baseurl = @"https://panshubeistorage.table.core.windows.net/";
            string tbname = "People";//Console.ReadLine();
            string sastoken = @"?sv=2019-10-10&ss=************";
            string filter = @"&$filter=PartitionKey%20eq%20'Smith'%20";
            baseurl = baseurl + tbname + "()" + sastoken+filter;
            HttpResponseData data = HttpHelper.GetForOData(baseurl);
            string responseData = data.Data.Replace(".","_");
            ODataResponse odata = JsonConvert.DeserializeObject<ODataResponse>(responseData);

            foreach (ODatavalue m in odata.value)
            {
                Console.WriteLine(m.PartitionKey + "    " + m.PhoneNumber + "    " + m.RowKey + "   " + m.Email);
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
        public class ODataResponse
        {
            public string odata_metadata { get; set; }
            public List<ODatavalue> value { get; set; }
        }
        public class ODatavalue {
            public string odata_type { get; set; }
            public string odata_id { get; set; }
            public string odata_etag { get; set; }
            public string odata_editLink { get; set; }
            public string Timestamp { get; set; }
            public string PartitionKey { get; set; }
            public string RowKey { get; set; }
            public string Email { get; set; }
            public string PhoneNumber { get; set; }
        }
    }
}
    static async Task Main(string[] args)
    {
        Console.WriteLine("Azure Cosmos Table Samples");
        Console.WriteLine("Query data by filter");

        CloudTable table = GetTable();

        Console.WriteLine("pls input PartitionKey:");
        string PartitionKey = Console.ReadLine();
        Console.WriteLine("pls input RowKey:");
        string RowKey = Console.ReadLine();
        //Query
        IQueryable<CustomerEntity> linqQuery = table.CreateQuery<CustomerEntity>()
        .Where(x => x.PartitionKey== PartitionKey && x.RowKey== RowKey)
        .Select(x => new CustomerEntity() { PartitionKey = x.PartitionKey, RowKey = x.RowKey, Email = x.Email, PhoneNumber= x.PhoneNumber });

        var list = linqQuery.ToList<CustomerEntity>();

        foreach (CustomerEntity m in list)
        {
            Console.WriteLine(m.PartitionKey+"    "+m.PhoneNumber+"    "+m.RowKey+"   "+m.Email);
        }
        Console.WriteLine();
        Console.WriteLine("Press any key to exit");
        Console.Read();
    }

    public static CloudTable GetTable() {
        CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=***x=core.windows.net");
        CloudTableClient tableClient = account.CreateCloudTableClient();
        CloudTable table = tableClient.GetTableReference("People");
        return table;
    }