![](/img/trans.png)
[英]Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Azure.Cosmos.Serialization.HybridRow.Result>
[英]Cannot convert Microsoft.Azure.Cosmos.Table.DynamicTableEntity to System.Threading.Task.Task<Microsoft.Azure.Cosmos.Table.DynamicTableEntity>
下面的方法在“await tableRecords.Add(newprops);”行給了我錯誤關於參數 newprops 說
無法轉換為 System.Threading.Task.Task<Microsoft.Azure.Cosmos.Table.DynamicTableEntity>。 我在這里做錯了什么??
我正在嘗試在我插入 Azure 表存儲的表記錄中添加新值。
public async Task WriteToTable( Stream lines, DataClass dataclass,
Func<Dictionary<string, EntityProperty>, Task<(string, string)>> genKeys,
Func<Dictionary<string, EntityProperty>, Task<List<string>>> generateColumns, List<string> columnsList, DynamicTableEntity tableEntry,
bool upsert )
{
const int BatchSize = 100;
if( HasPartitionAndRowKey( dataclass.TableSchema.Fields ) )
{
genKeys = ( Dictionary<string, EntityProperty> props ) => Task.FromResult( (props["PartitionKey"].StringValue, props["RowKey"].ToString()) );
}
var tableRecords = ReadCSV( lines, dataclass.TableSchema.Fields )
.Select( async props =>
{ var (partitionKey, rowKey) = await genKeys( props );
return new DynamicTableEntity( partitionKey, rowKey, string.Empty, props );
} ).ToList();
if( columnsList != null )
{
var newColumnValues = ReadCSV( lines, dataclass.TableSchema.Fields )
.Select( async prop => { await generateColumns( prop ); } ).ToList();
var arr = newColumnValues.ToArray();
var newprops = new DynamicTableEntity();
for( int i = 0; i < columnsList.Count; i++ )
{
newprops.Properties.Add( columnsList[i], EntityProperty.CreateEntityPropertyFromObject( arr[i] ) );
await tableRecords.Add( newprops );
}
await BatchInsertIntoTableStorage( BatchSize, tableRecords, upsert );
}
await BatchInsertIntoTableStorage( BatchSize, tableRecords, upsert );
}
您不需要await
tableRecords.Add(newprops);
. Awaiting 用於async
功能,而
您的 tableRecords 已經是一個列表:
var tableRecords = ReadCSV( lines, dataclass.TableSchema.Fields )
.Select( async props =>
{ var (partitionKey, rowKey) = await genKeys( props );
return new DynamicTableEntity( partitionKey, rowKey, string.Empty, props );
} ).ToList();
更改await tableRecords.Add( newprops );
到tableRecords.Add( newprops );
你會沒事的。
基本上你的錯誤說的是它不能等待void
public void Add (T item);
它需要等待一個Task
,而這不是 add 返回的。
以上所有內容都是有效的,但您還需要打破您的 select 並等待。 WhenAll
完成后,創建您的列表。
var tasks = await Task.WhenAll(ReadCSV( lines, dataclass.TableSchema.Fields)
.Select( async props = await genKeys( props )));
var tableRecords = tasks.Select((partitionKey, rowKey) => new DynamicTableEntity(partitionKey, rowKey, string.Empty, props )).ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.