Xav*_* Sc 2 c# linq async-await
我有这个查询,我找不到正确的方法来获得价格(.Amount.GetValueOrDefault()).
private IEnumerable<Product> GetSubsciptionOffers(IEnumerable<StripeProduct> productList)
{
return productList
.Select(async product => new Product
{
Name = product.Name,
Id = product.Id,
Image = new Uri(product.Images.First()),
Description = product.Description,
OfferType = OfferTypeEnum.Pro,
Price = await _planRepo.GetPlanByIdAsync(product.Metadata.First().Value).Amount.GetValueOrDefault()
});
}
Run Code Online (Sandbox Code Playgroud)
错误是:
任务不包含金额的定义
你必须用括号括起来await:
Price = (await _planRepo.GetPlanByIdAsync(product.Metadata.First().Value)).Amount.GetValueOrDefault()
Run Code Online (Sandbox Code Playgroud)
原因是.运营商的优先级高于await.
| 归档时间: |
|
| 查看次数: |
100 次 |
| 最近记录: |