I am trying to bind a gridview using EF 6.0 raw Sql query with Async, but the system goes on for endless execution and task.Result is never populated.
What I have tried:
protected void Page_Load(object sender, EventArgs e)
{
var task = LoadDataAsync();
task.Wait();
var data = task.Result;
GridView1.DataSource = data;
GridView1.DataBind();
}
private async Task<list<user>> LoadDataAsync()
{
List<user> users = null;
using (var context = new BlogEntities())
{
users = await context.Users.SqlQuery("Select * from [User]").ToListAsync();
}
return users;
}
Can anyone please let me know, how to call the async method and get the data bind successfully.