我有这个功能:
public async Task<IEnumerable<RegionBreif>> GetAsync()
{
return await Table.Where(x => x.SiteId == _siteId).Select(r => new RegionBreif
{
IsServiceable = await RegionBreif.checkIfServicable(Context, r.SiteId, r.Id)
}).ToArrayAsync();
}
这个功能:
public static async Task<bool?> checkIfServicable(DbContext context, int? _siteId, int _regionId)
{
var t = (from ir in context.Set<InspectionReview>()
join so in context.Set<SiteObject>() on ir.ObjectId equals so.Id
where so.SiteRegionId == _regionId && so.SiteId == _siteId
select (bool?)
ir.IsNormal);
return t.Count() == 0 ? (bool?)null : t.Any(x => x.Value == false) ? false : true;
}
在这一行:
await RegionBreif.checkIfServicable(Context, r.SiteId, r.Id)
我收到此错误:
错误13&#39; await&#39;运算符只能在异步lambda表达式中使用。考虑使用&#39; async&#39;标记这个lambda表达式。改性剂。
答案 0 :(得分:3)
问题在于传递给Select
的lambda表达式。如果您想使用类型create await
中的RegionBreif
,则必须传递async
lambda表达式,如下所示:
Select(async r => new RegionBreif
{
IsServiceable = await RegionBreif.checkIfServicable(Context, r.SiteId, r.Id)
})