[英]Cannot convert Microsoft.Azure.Cosmos.Table.DynamicTableEntity to System.Threading.Task.Task<Microsoft.Azure.Cosmos.Table.DynamicTableEntity>
Below method gives me error at line "await tableRecords.Add( newprops );"下面的方法在“await tableRecords.Add(newprops);”行给了我错误on parameter newprops saying
关于参数 newprops 说
cannot convert to System.Threading.Task.Task<Microsoft.Azure.Cosmos.Table.DynamicTableEntity>.
无法转换为 System.Threading.Task.Task<Microsoft.Azure.Cosmos.Table.DynamicTableEntity>。 What wrong am I doing here??
我在这里做错了什么??
I am trying to add new values in my table records which I am inserting in an Azure table storage.我正在尝试在我插入 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 );
}
You do not need to await
the tableRecords.Add(newprops);
您不需要
await
tableRecords.Add(newprops);
. . Awaiting is meant for
async
functions while Awaiting 用于
async
功能,而
Your tableRecords are a list already:您的 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();
Change await tableRecords.Add( newprops );
更改
await tableRecords.Add( newprops );
to tableRecords.Add( newprops );
到
tableRecords.Add( newprops );
and you'll be fine.你会没事的。
Basically what your error says is that it can't await void
基本上你的错误说的是它不能等待
void
public void Add (T item);
It needs to await a Task
and that's not what add returns.它需要等待一个
Task
,而这不是 add 返回的。
All the above is valid, but you also need break your select and await.以上所有内容都是有效的,但您还需要打破您的 select 并等待。
WhenAll
are done, create your list. 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.