I am learning ASP.NET Core and Razor Pages. In my practice project, I am trying to execute a select query on a database which I have added through migrations (code-first).
Here is the code:
public string DataTest()
{
var data = CheckDbEntryAsync();
var d1 = data.ToString();
return data.ToString();
}
public async Task<List<UserData>> CheckDbEntryAsync()
{
List<UserData> data;
data = await _context.UserDataItems.FromSql("SELECT * from dbo.UserDataItems").ToListAsync();
return data;
}
The output (the value of 'data.ToString()' or variable 'd1') is:
"System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[System.Collections.Generic.List`1[LearnASP.Models.UserData],LearnASP.Controllers.UserManagerController+<CheckDbEntryAsync>d__6]"
I can't figure out how to make sense of this...shouldn't this be a list that contains values from the table?
The value of 'data' before the CheckDbEntryAsync is executed is:
Id = 242, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"
Here is my UserDataDbContext.cs:
public class UserDataDbContext : DbContext
{
public DbSet<UserData> UserDataItems { get; set; }
public UserDataDbContext(DbContextOptions<UserDataDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
}
I can't figure out where exactly I am going wrong...is it the query which is not executing...or it is something else...there are no error messages.
Please help, Thanks
>`
> ??
– D Navi Apr 17 '19 at 07:36