Reputation: 13614
I have this function:
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();
}
And this function:
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;
}
On this row:
await RegionBreif.checkIfServicable(Context, r.SiteId, r.Id)
I get this error:
Error 13 The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.
Upvotes: 1
Views: 1992
Reputation: 53958
The problem is in the lambda expression you pass to the Select
. If you want to make use of the await
inside the type create, RegionBreif
, you have to pass an async
lambda expression as below:
Select(async r => new RegionBreif
{
IsServiceable = await RegionBreif.checkIfServicable(Context, r.SiteId, r.Id)
})
Upvotes: 3