我正在使用Azure cosmos DB表。
在以下代码中,调用result.ToList()挂起。
我尝试了几种选项,例如TCP和HTTP。
但是,如果我使MVC控制器异步并使用异步查询,那么一切正常。
但由于这是一个旧的应用程序,我无法将所有控制器和相应的调用更改为async
private static string GetFinalFilter(Guid section, string page, string property, string lang)
{
string partitionKeyFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, GetPartitionKey(page));
string sectionFilter = TableQuery.GenerateFilterConditionForGuid("Section", QueryComparisons.Equal, section);
string pageFilter = TableQuery.GenerateFilterCondition("Page", QueryComparisons.Equal, page);
string propertyFilter = TableQuery.GenerateFilterCondition("Property", QueryComparisons.Equal, property);
string languageFilter = TableQuery.GenerateFilterCondition("Language", QueryComparisons.Equal, lang);
string finalFilter = TableQuery.CombineFilters(TableQuery.CombineFilters(partitionKeyFilter, TableOperators.And, sectionFilter), TableOperators.And,
TableQuery.CombineFilters(pageFilter, TableOperators.And, TableQuery.CombineFilters(propertyFilter, TableOperators.And, languageFilter)));
return finalFilter;
}
private static string ProductIsNotDefinedSectionIsNotDefined(string page, string property, string lang, string defaultLang)
{
string finalFilter = GetFinalFilter(Guid.Empty, page, property, lang);
TableQuery<MDEntity> tableQuery = new TableQuery<MDEntity>().Where(finalFilter);
var result = mdTable.ExecuteQuery<MDEntity>(tableQuery);
var list = result.ToList();
答案 0 :(得分:0)
从异步开始是非常危险的 - &gt;同步 - &gt;异步,它会给你死锁。 您可以做的是在async Executioncall to Cosmos write,.GetAwaiter()。GetResult()上,然后强制它实际返回结果。