-
-
Save MrMikeFloyd/dacb049eaa1d35bd4f93eb02728a9f39 to your computer and use it in GitHub Desktop.
| using System.IO; | |
| using Microsoft.Azure.WebJobs; | |
| using Microsoft.Azure.WebJobs.Extensions.Http; | |
| using Microsoft.AspNetCore.Http; | |
| using Microsoft.Azure.WebJobs.Host; | |
| using Newtonsoft.Json; | |
| using System; | |
| using Microsoft.WindowsAzure.Storage.Table; | |
| using System.Collections.Generic; | |
| using System.Net.Http; | |
| using System.Net; | |
| using System.Text; | |
| namespace Company.Function | |
| { | |
| public class TabEntity : TableEntity | |
| { | |
| public Int32 rowX { get; set; } | |
| public Int32 rowY { get; set; } | |
| public Int32 rowZ { get; set; } | |
| } | |
| public static class HttpTrigger | |
| { | |
| [FunctionName("HttpTrigger")] | |
| public static HttpResponseMessage Run( | |
| [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req, | |
| [Table("sampletable")] CloudTable tab, | |
| TraceWriter log) | |
| { | |
| log.Info("Kicking off."); | |
| // Load data from TableStorage using CloudTable | |
| var querySegment = tab.ExecuteQuerySegmentedAsync(new TableQuery<TabEntity>(), null); | |
| StringContent responseContent = null; | |
| foreach (TabEntity item in querySegment.Result) | |
| { | |
| log.Info($"Data loaded: '{item.PartitionKey}' | '{item.RowKey}' | '{item.rowX}' | '{item.rowY}'"); | |
| responseContent = new StringContent(JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json"); | |
| } | |
| log.Info("Done."); | |
| return new HttpResponseMessage(HttpStatusCode.OK){ | |
| Content = responseContent | |
| }; | |
| } | |
| } | |
| } |
| { | |
| "IsEncrypted": false, | |
| "Values": { | |
| "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=xyz;AccountKey=01234567890", | |
| "AzureWebJobsDashboard": "" | |
| } | |
| } |
@yzorg sorry for the late response. Your assumption is accurate. This is a very minimal example to demonstrate accessing TableStorage, so don't expect any serious functionality here :)
it was very useful for me. solved my problem. also tell how can I add condition in query like filter in this statement tab.ExecuteQuerySegmentedAsync(new TableQuery(), null);
it was very useful for me. solved my problem. also tell how can I add condition in query like filter in this statement tab.ExecuteQuerySegmentedAsync(new TableQuery(), null);
Glad to hear it helped @Preeti1910! TableQuery supports "Builder Pattern"-Style Where clauses like so (Example taken from the official docs found here: var tableQuery = new TableQuery() .where('Name == ? or Name <= ?', 'Person1', 'Person2'); .or('Age >= ?', 18);
You're assigning to
responseContentinside theforeachloop. If I'm reading that correctly you're only sending the last row of the table, but doing the work to deserialize all rows. That was intentional?