title: How to reach out related data in razor page. EF Core 5.0
body: <p>I'm trying to get <code>Product</code> data with its <code>ProductComments</code> but I'm getting null error when I ask for it. There is a one-to-many relation between <code>Product</code> and <code>ProductComments</code>.</p>
  <p>Let me show you my data access layer:</p>
  <pre><code>public interface IRepositoryProduct&lt;T&gt; : IRepository&lt;Product&gt;
  {
      List&lt;Product&gt; GetProductWithComment();
  }
  
  public class RepositoryProduct&lt;T&gt; : Repository&lt;Product&gt;, IRepositoryProduct&lt;T&gt;
  {
      public RepositoryProduct(TradeTurkDBContext context) : base(context) { }
  
      public List&lt;Product&gt; GetProductWithComment()
      {
          return TradeTurkDBContext.Products.Include(x =&gt; x.ProductComment).ToList();
      }
  }
  </code></pre>
  <p>And this is my view model class:</p>
  <pre><code>public class ProductCommentViewModel
  {
      public Product Product { get; set; }
      public List&lt;Product &gt; ProductsC { get; set; }
  }
  </code></pre>
  <p>and here is my controller:</p>
  <pre><code>var ListProductComment = _unitOfWorkP.RepositoryProduct.GetProductWithComment();
  var Product= new Product();
  var ProductCommentViewModel = new ProductCommentViewModel
          {
              Product= Product,
              ProductsC= ListProductComment
          };
  return View(ProductCommentViewModel);
  </code></pre>
  <p>When I check out if there is a data inside of <code>Product</code>, it tells me there is a 2 comment inside of <code>ProductComments</code>.</p>
  <p>Let me show you how I am trying to reach that data in <code>cshtml</code>:</p>
  <pre><code>@foreach (var item in Model.ProductsC)
  {
      &lt;tr&gt;
          &lt;td class=&quot;text-center&quot;&gt;
              &lt;div class=&quot;dropdown custom-dropdown&quot;&gt;
              &lt;a class=&quot;dropdown-toggle&quot; href=&quot;#&quot; role=&quot;button&quot; id=&quot;dropdownMenuLink1&quot; data-toggle=&quot;dropdown&quot; aria-haspopup=&quot;true&quot; aria-expanded=&quot;false&quot;&gt;
              &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;
                                               class=&quot;feather feather-more-horizontal&quot;&gt;
                  &lt;circle cx=&quot;12&quot; cy=&quot;12&quot; r=&quot;1&quot;&gt;&lt;/circle&gt;
                  &lt;circle cx=&quot;19&quot; cy=&quot;12&quot; r=&quot;1&quot;&gt;&lt;/circle&gt;
                  &lt;circle cx=&quot;5&quot; cy=&quot;12&quot; r=&quot;1&quot;&gt;&lt;/circle&gt;
              &lt;/svg&gt;
              &lt;/a&gt;
              &lt;div class=&quot;dropdown-menu&quot; aria-labelledby=&quot;dropdownMenuLink1&quot; style=&quot;will-change: transform;&quot;&gt;
                  &lt;!-- SONRA YAPILACAK &lt;a class=&quot;dropdown-item&quot; href=&quot;user_profile.php?userID=&quot;&gt;Görüntüle&lt;/a&gt;--&gt;
                  // this is the point where I get error  
                  &lt;a id=&quot;@item.ProductComment.CommentID&quot; class=&quot;dropdown-item&quot; data-toggle=&quot;modal&quot; data-target=&quot;#productCommentUpdate-@item.ProductComment.CommentID&quot;&gt;Güncelle&lt;/a&gt;
                  &lt;a id=&quot;@item.ProductComment.CommentID&quot; class=&quot;dropdown-item&quot; data-toggle=&quot;modal&quot; data-target=&quot;#productCommentDelete-@item.ProductComment.CommentID&quot;&gt;Sil&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/td&gt;
      &lt;td&gt;@item.ProductComment.CommentID&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.ShoppingUserID&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.ShoppingUserID&lt;/td&gt;
      &lt;td&gt;@item.ProductID&lt;/td&gt;
      &lt;td&gt;&lt;button class=&quot;btn btn-outline-dark mb-2&quot; data-toggle=&quot;modal&quot; data-target=&quot;#productCommentView-@item.ProductComment.CommentID&quot;&gt;Yorumu Görüntüle&lt;/button&gt;&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.CreatedUserId&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.ModifiedUserId&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.CreatedUserType&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.ModifiedUserType&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.CreatedDate&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.ModifiedDate&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.ProductCommentIsActive&lt;/td&gt;
      &lt;td&gt;@item.ProductComment.IsDeleted&lt;/td&gt;
  &lt;/tr&gt;
  }
  </code></pre>
  <h2>Thanks for any suggestion !</h2>
  <p>i edit my question but im still gettin that error</p>