简体   繁体   English

无法将 Microsoft.Azure.Cosmos.Table.DynamicTableEntity 转换为 System.Threading.Task.Task <microsoft.azure.cosmos.table.dynamictableentity></microsoft.azure.cosmos.table.dynamictableentity>

[英]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 返回的。

Wait for select等待 select

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();

Async await in linq select linq select 中的异步等待

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到方法:'System.Threading.Tasks.Task`1 <microsoft.azure.cosmos.serialization.hybridrow.result></microsoft.azure.cosmos.serialization.hybridrow.result> - Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Azure.Cosmos.Serialization.HybridRow.Result> 反序列化从Azure表检索的DynamicTableEntity - Deserialize a DynamicTableEntity retrieved from Azure Table 有Task的麻烦获得Task结果(无法将System.Threading.Task.Task隐式转换为string []) - Troubles with Task getting Task result (cannot implicitly convert System.Threading.Task.Task to string[]) 使用存储库模式将DynamicTableEntity写入Azure表存储时出现问题 - Issue writing a DynamicTableEntity to Azure table storage using repository patterns Azure function 异常 - 将日志写入表存储时出错:Microsoft.Azure.Cosmos.Table.StorageException - Azure function exception - Error writing logs to table storage: Microsoft.Azure.Cosmos.Table.StorageException Microsoft.Azure.Cosmos.Table 和 Microsoft.WindowsAzure.Storage 之间的 ExecuteQuerySegmentedAsync 性能显着下降 - Significant performance degration on ExecuteQuerySegmentedAsync between Microsoft.Azure.Cosmos.Table and Microsoft.WindowsAzure.Storage 在 Microsoft.Azure.Cosmos.Table 中使用 TableEntity.Flatten 的正确方法是什么? - What is the right way to use TableEntity.Flatten in Microsoft.Azure.Cosmos.Table? 如果是全局复制,Microsoft.Azure.CosmosDB.Table是否会自动选择到cosmos DB的最低延迟路由? - Does Microsoft.Azure.CosmosDB.Table automatically choose the lowest latency route to the cosmos DB if replicated globally? C# Azure - 从 Microsoft.Azure.Cosmos.Table 移动到 Azure.Data.Tables 后找不到指定的资源 - C# Azure - Specified Resource not found after moving from Microsoft.Azure.Cosmos.Table to Azure.Data.Tables 并行连接到 Microsoft Azure Cosmos DB - Parallel connection to Microsoft Azure Cosmos DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM