如何在C#(doc)中使用OData过滤器查询表?请提供相同的示例吗?
您可以使用LinQ像所支持的文档一样进行查询。
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;
}