Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entities Framework 6 alpha 2 - Async Patterns

I recently have a project with MVC 4, .NET 4.5 and using EF 5.0 (Database First) using the EF 5.0 DbContext Generator. I then upgraded through Nuget Manager to EF 6.0 alpha 2. I wanted to use the new async patterns but for some reason I dont have .ToListAsync() available. I am referencing the context in a similiar fashion:

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

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

        return View(keywords);
    }
}

Is this not available in Database First, and only available in Code First? How can I make something like the example above work? I am using SQL Azure.

like image 603
Joe Avatar asked Dec 30 '12 20:12

Joe


1 Answers

Async. extension methods are defined in EF related System.Data.Entity.IQueryableExtensions static class. So you must add:

using System.Data.Entity;

at the beginning of your controller class file to be able to call them.

like image 188
Ladislav Mrnka Avatar answered Sep 28 '22 08:09

Ladislav Mrnka