Entities Framework 6 alpha 2 - Async Patterns

asp.net-mvc asp.net-mvc-4 azure-sql-database c# entity-framework-6

Question

In a recent project, I used the EF 5.0 DbContext Generator, MVC 4,.NET 4.5, and EF 5.0 (Database First). I then upgraded to EF 6.0 alpha 2 using Nuget Manager. I intended to utilize the new async patterns, but I don't have them for some reason. ToListAsync() is accessible. In a similar vein, I'm mentioning the context:

public class HomeController : Controller
{
    TestContext db = new TestContext();

    public async Task<ActionResult> Index()
    {
        var keywords = await db.Keywords.ToListAsync();

        return View(keywords);
    }
}

Is this just possible in Code First and not Database First? How would I go about making the previous example work? SQL Azure is what I use.

1
5
12/30/2012 9:03:03 PM

Accepted Answer

In EF related, async. extension methods are defined.System.Data.Entity.IQueryableExtensions static type. hence you must include:

using System.Data.Entity;

in order to be able to call them, include them at the top of your controller class file.

8
12/30/2012 8:59:07 PM

Popular Answer

I believe you can utilize Task. Like this, run.

public async Task<ActionResult> Index()
{
    var keywords = await Task.Run(() => db.Keywords.ToList());

    return View(keywords);
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow