1
var kusto = string.Format("let MyData = CompanyMydata" +
                " | where ID == 'Z123' | top 1 by dateTimeUtc desc");

            var reader = client.ExecuteQuery(kusto);
            while (reader.Read())
            {
                //how can i return coming result as list of string or json string?
            } 

while loop我可以通过使用一一返回单列值, string state = reader.GetString(1);但我想返回完整结果而不是一一列值。这样我就可以JsonConvert.DeserializeObject<T>(resultString);对特定的课程进行操作。

4

1 回答 1

3

假设您使用的是此处提到的客户端库,您应该能够执行以下操作:

    static void Main(string[] args)
    {
        var kcsb = new KustoConnectionStringBuilder("https://help.kusto.windows.net").WithAadUserPromptAuthentication();
        var databaseName = "Samples";

        using (var queryProvider = KustoClientFactory.CreateCslQueryProvider(kcsb))
        {
            var clientRequestProperties = new ClientRequestProperties() { ClientRequestId = "Sample;" + Guid.NewGuid() };
            var query = "StormEvents | summarize count(), max(EndTime) by State";
            var result = queryProvider.ExecuteQuery<MyType>( // focus on this part
                databaseName,
                query,
                clientRequestProperties)
                .ToList();

            foreach (var row in result)
            {
                Console.WriteLine($"State = {row.State}, Count = {row.Count}, MaxEndTime = {row.MaxEndTime}");
            }
        }
    }

    class MyType
    {
        public string State;
        public long Count;
        public DateTime MaxEndTime;
    }
于 2019-02-23T18:56:54.200 回答