Hi everybody,
I have created a very simple test method to play with async methods of EF6 but this just doesn't work with await. I cannot get the exception if there is ever one here (in all honesty, I didn't try that hard to find it). Here is the code:
publicclass AccommProperty { publicint AccommPropertyID { get; set; } publicstring PropertyName { get; set; } } publicclass MyContext : DbContext { public MyContext() : base("Hotels") { } public IDbSet<AccommProperty> AccommProperties { get; set; } } class Program { staticvoid Main(string[] args) { GetHotelsAsync().ContinueWith(task => { var hotels = task.Result; foreach (var hotel in hotels) { Console.WriteLine(hotel.PropertyName); } Console.ReadLine(); }); } static async Task<IEnumerable<AccommProperty>> GetHotelsAsync() { using (MyContext ctx = new MyContext()) { var hotels = await ctx.AccommProperties.ToListAsync(); return hotels; } } }
The AccommProperties table is not empty, there are 247 records inside it.
Also, the following code works perfectly fine:
publicclass AccommProperty { publicint AccommPropertyID { get; set; } publicstring PropertyName { get; set; } } publicclass MyContext : DbContext { public MyContext() : base("Hotels") { } public IDbSet<AccommProperty> AccommProperties { get; set; } } class Program { staticvoid Main(string[] args) { MyContext ctx = new MyContext(); ctx.AccommProperties.ToListAsync().ContinueWith(task => { var hotels = task.Result; foreach (var hotel in hotels) { Console.WriteLine(hotel.PropertyName); } }); Console.ReadLine(); } }
Not sure what I am missing here or there is anything wrong with the EF here.