我有以下方法返回一个IAsyncEnumerable<T>
:
async IAsyncEnumerable<T> RunReport()
{
var handler = new HttpClientHandler();
var client = new HttpClient(handler);
client.BaseAddress = new Uri("");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var settings = new JsonSerializerSettings();
var jsonFormatter = new JsonMediaTypeFormatter() { SerializerSettings = settings };
var requestMessage = new HttpRequestMessage(HttpMethod.Get, "api/controler");
var response = await client.SendAsync(requestMessage);
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync())
{
using (var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
var linesJson = await reader.ReadLineAsync();
var line = JsonConvert.DeserializeObject<List<T>>(linesJson, jsonFormatter.SerializerSettings);
foreach (var line in lines)
yield return line;
}
}
}
}
我想使用SqlBulkCopy
'sWriteToServerAsync
方法将该结果流传输到数据库,但无法弄清楚如何将其转换为's 重载列表IDataReader
中的任何其他类型。WriteToServerAsync
我愿意使用除批量复制之外的其他东西,只要它性能合理。