-3

I get compile time error:"Products does not contain a definition for GetAwaiter " with the following code. I could not figure out why , Please somebody help me!! Thanks!!

public async Task<IActionResult> Edit(int? id)
    {
        if (id == null)
        {
            return NotFound();
        }
        ProductsVM.Products =  await _db.Products.Include(m => m.SpecialTags).Include(m => m.ProductTypes).SingleOrDefault(m => m.Id == id);
        if (ProductsVM.Products == null)
        {
            return NotFound();
        }
        return View(ProductsVM);
    }
RajDhruba
  • 7
  • 4
  • 4
    why `await` on a synchronus call? remove that – Rahul Dec 03 '18 at 12:21
  • 1
    Possible duplicate of [Task<> does not contain a definition for 'GetAwaiter'](https://stackoverflow.com/questions/11853812/task-does-not-contain-a-definition-for-getawaiter) – LenglBoy Dec 03 '18 at 12:23
  • sorry for the incomplete code. This is my async function:public async Task Edit(int? id) { if (id == null) { return NotFound(); } ProductsVM.Products = await _db.Products.Include(m => m.SpecialTags).Include(m => m.ProductTypes).SingleOrDefault(m => m.Id == id); if (ProductsVM.Products == null) { return NotFound(); } return View(ProductsVM); } – RajDhruba Dec 03 '18 at 12:25
  • Hello there. Please take an opportunity to read [ask]. You can edit your question to update your code in the question so it's formatted properly. Putting the code in the comments, as you can see, produces unreadable code. Also, always provide a [mcve]. – rory.ap Dec 03 '18 at 12:29

1 Answers1

1

You're not using the async versions of LINQ so there's nothing to await, which results in that error. Here's an overview of a lot of async methods you can use with LINQ:
https://learn.microsoft.com/en-us/dotnet/api/system.data.entity.queryableextensions?view=entity-framework-6.2.0

Edit:
It contains a SingleOrDefaultAsync() version which should work