title: Computed properties in a PageModel
body: <p>I have a subclass of <code>PageModel</code> that looks like this:</p>
  <pre><code>public class DetailsModel : PageModel
  {
      ...
      public IList&lt;Comment&gt; Comments { get; set; }
      ...
  
      public async Task&lt;IActionResult&gt; OnGetAsync(int? id)
      {
          Comments = await _context.Comment.Where(comment =&gt; comment.LinkId == id).ToListAsync();
  
          ...
      }
      ...
  }
  </code></pre>
  <h1>Moving the code to the property definition</h1>
  <p>Instead of computing the property value inside <code>OnGetAsync</code>, I had considered having the computation code be at the property definition site:</p>
  <pre><code>    public IList&lt;Comment&gt; Comments
      {
          get
          {
              return _context.Comment.Where(comment =&gt; comment.LinkId == Link.Id).ToList();
          }
      }
  </code></pre>
  <p>One downside there is that the code is no longer async.</p>
  <p>The code runs each time the property is called (which may or may not be desired).</p>
  <h1>Putting the code in a method</h1>
  <p>Finally, I can put the code in a method instead of a property:</p>
  <pre><code>    public async Task&lt;IList&lt;Comment&gt;&gt; Comments()
      {
          return await _context.Comment.Where(comment =&gt; comment.LinkId == Link.Id).ToListAsync();
      }
  </code></pre>
  <p>Now it's async again. But we have a little syntactic overhead at the callsite:</p>
  <pre><code>await Comments()
  </code></pre>
  <p>I.e. we need to use <code>await</code> and the parens.</p>
  <h1>Question</h1>
  <p>I like the second approach as the code is kept close to the property definition. This is especially nice when there are many properties. (It seems awkward to have a long list of property definitions only to set them up later in <code>OnGet</code>.) But as mentioned, there are a couple of potential downsides.</p>
  <p>What is the idiomatic and recommended way to do something like this?</p>