title: Simple SQL Query in ASP.NET Razor
body: <p>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).</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public string DataTest()
  {
      var data = CheckDbEntryAsync();
      var d1 = data.ToString();
      return data.ToString();
  }
  
  public async Task&lt;List&lt;UserData&gt;&gt; CheckDbEntryAsync()
  {
     List&lt;UserData&gt; data;
  
     data = await _context.UserDataItems.FromSql("SELECT * from dbo.UserDataItems").ToListAsync();
  
     return data;
  }
  </code></pre>
  
  <p>The output (the value of 'data.ToString()' or variable 'd1') is:</p>
  
  <pre><code>"System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[System.Collections.Generic.List`1[LearnASP.Models.UserData],LearnASP.Controllers.UserManagerController+&lt;CheckDbEntryAsync&gt;d__6]"
  </code></pre>
  
  <p><strong>I can't figure out how to make sense of this...shouldn't this be a list that contains values from the table?</strong> </p>
  
  <p>The value of 'data' before the CheckDbEntryAsync is executed is:</p>
  
  <pre><code>Id = 242, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"
  </code></pre>
  
  <p>Here is my UserDataDbContext.cs:</p>
  
  <pre><code>public class UserDataDbContext : DbContext
  {
      public DbSet&lt;UserData&gt; UserDataItems { get; set; }
  
      public UserDataDbContext(DbContextOptions&lt;UserDataDbContext&gt; options) : base(options)
      {
  
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
      }
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>Please help, 
  Thanks</p>