1
votes

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.

1

1 Answers

3
votes

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)
})