Stored asynchronous Procedure

Asked

Viewed 132 times

1

When trying to run Process asynchronously

public async Task<ActionResult> Index()
    {
        Stopwatch watch = new Stopwatch();
        watch.Start();
        ContentManagement service = new ContentManagement();
        var contentTask = service.MesesAsync();
        var content = await contentTask;
        watch.Stop();                    
        ViewBag.WatchMilliseconds = watch.ElapsedMilliseconds;
        return View("Index");
     }

public async Task<List<SP_MESES_BUSCA_Result>> MesesAsync()
    {
        var ListarMes = await db.SP_MESES_BUSCA().ToList();
        return ListarMes;
    }

Returns the error:

Cannot await 'System.Collections.Generic.List'

1 answer

2

The await in his method MesesAsync() is expecting an asynchronous instruction.

Just change the ToList() for ToListAsync() that will work.

Your code will look like this;

public async Task<List<SP_MESES_BUSCA_Result>> MesesAsync()
    {
        var ListarMes = await db.SP_MESES_BUSCA().ToListAsync();
        return ListarMes;
    }
  • This error appears now "does not contain a Definition for 'Tolistasync' and the best Extension method Overload 'Queryableextensions.Tolistasync(Iqueryable)'" if you enter ". Asqueryable() the most error when executing appears Only sources that implement Idbasyncenumerable can be used for Entity Framework asynchronous Operations. For more Details see "

  • Add this reference to your project: using System.Data.Entity;

  • I’m already using, if I do a table works, now with the past of these errors.

  • Behold this tutorial

Browser other questions tagged

You are not signed in. Login or sign up in order to post.