I'm working with Identity 2.0 in MVC5, and I'm trying to get the first role for the current user.
This bit of code doesn't report any errors:
var DatabaseContext = new ApplicationDbContext(); var thisUserAccount = DatabaseContext.Users.FirstAsync(u => u.Id == Id); This bit of code:
var DatabaseContext = new ApplicationDbContext(); var thisUserAccount = await DatabaseContext.Users.FirstAsync(u => u.Id == Id); reports the following error:
The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'
The method is an asynchronous method, so why cant I use "await"?
Also, will calling:
DatabaseContext.Users.Load(); before the FirstAsync optimise things a bit (rather than building a ToList which I'm assuming FirstSync does)?
I'm still trying to get to grips with what the async stuff can do, so any useful links will be much appreciated.