Wrap the synchronous method in asynchronous, which you can "wait"
I have a synchronous call:
_context.User.Where((u) => (u.UserID == twitterId && u.Type == UserType.Show)).SingleOrDefault(); What I need to wrap in async, which I can wait with the await keyword.
How can i achieve this?
Thanks.
You need to wrap your synchronization call using the Task.Run method.
var user = await Task.Run(() => _context.User .Where(u => u.UserID == twitterId && u.Type == UserType.Show) .SingleOrDefault()); Keep in mind that EntityFramework in version 6.0 will have asynchronous interfaces, so you no longer need to use this code.
QueryableExtensions added in EF6 takes this step:
await _context.User.SingleOrDefaultAsync(u => u.UserID == twitterId && u.Type == UserType.Show); Remember to specify System.Data.Entity in EntityFramework.dll