Multi-async in Entity Framework 6?

asynchronous entity-framework entity-framework-6

Accepted Answer

One asynchronous operation per context is permitted at a time, as is made apparent by the exception.

So, you must choose betweenawait as the error notice advises, one at a time:

var banner = await context.Banners.ToListAsync();
var newsGroup = await context.NewsGroups.ToListAsync();

Or you might employ several contexts:

var banner = context1.Banners.ToListAsync();
var newsGroup = context2.NewsGroups.ToListAsync();
await Task.WhenAll(banner, newsGroup);
116
12/17/2013 1:10:20 PM

Popular Answer

Consider using the "transient" or "PerWebRequest" type for your lifecycle if you are using an IoC container for the injection of your Data Provider.

Like this: https://github.com/castleproject/Windsor/blob/master/docs/lifestyles.md



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