(u.UserID == twitterId &&...">

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.

+8
c # asynchronous windows-phone-8
source share
2 answers

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.

+12
source share

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

+3
source share

All Articles