title: Include in Entity Framework Core is not working properly
body: <p>I'm trying to show the brand name and product color and product size in user basket. I use ASP.NET Core 3.1 for this project.</p>
  <p>I used this query with <code>include</code>:</p>
  <pre><code>public IEnumerable&lt;UserBasket&gt; GetUserBasket(int userId)
      {
          return _context.UserBaskets
              .Include(p=&gt;p.Product)
              .Include(b=&gt;b.ProductBrand)
              .Include(s=&gt;s.ProductSize)
              .Include(c=&gt;c.ProductColor)
              .Where(u=&gt;u.UserId==userId)
              .ToList();
      }
  </code></pre>
  <p>and this is the action:</p>
  <pre><code>public IActionResult ShowOrders()
  {
      var userId = _userService.GetUserIdByUserName(User.Identity.Name);
      return View(_orderService.GetUserBasket(userId));
  }
  </code></pre>
  <p>and this is the view of the action:</p>
  <p>I used table to show the user basket</p>
  <pre><code>@model IEnumerable&lt;UserBasket&gt;
  
   @foreach (var item in Model)
                          {
                              &lt;tr class=&quot;gradeA odd&quot;&gt;
                                  &lt;td class=&quot;sorting_1&quot;&gt;@item.Product.Name&lt;/td&gt;
                                  &lt;td class=&quot;center &quot;&gt;@item.Count&lt;/td&gt;
                                  &lt;td class=&quot;center &quot;&gt;@item.SumPrice&lt;/td&gt;
                                  &lt;td class=&quot;center &quot;&gt;@item.CreateDate.Value.ToShamsi()&lt;/td&gt;
                                  &lt;td class=&quot;center &quot;&gt;@item.ProductBrand.BrandName&lt;/td&gt;
                                  &lt;td class=&quot;center &quot;&gt;@item.Size&lt;/td&gt;
                                  &lt;td class=&quot;center &quot;&gt;@item.Color&lt;/td&gt;
                                  @if (item.IsFinally)
                                  {
                                      &lt;td class=&quot;center &quot;&gt;&lt;i class=&quot;glyphicon-ok&quot;&gt;&lt;/i&gt;&lt;/td&gt;
                                  }
                                  else
                                  {
                                      &lt;td class=&quot;center &quot;&gt;&lt;i class=&quot;glyphicon-remove&quot;&gt;&lt;/i&gt;&lt;/td&gt;
                                  }
                              &lt;/tr&gt;
                          }
  </code></pre>
  <p>This is UserBasket class:</p>
  <pre><code>public class UserBasket
  {
      public UserBasket()
      {
  
      }
      [Key]
      public int UB_Id { get; set; }
      public int UserId { get; set; }
      public int ProductId { get; set; }
      public int PB_Id { get; set; }
      public int PC_Id { get; set; }
      public int PS_Id { get; set; }
      public int Count { get; set; }
      public int SumPrice { get; set; }
      public bool IsFinally { get; set; }
      public DateTime? CreateDate { get; set; }
      [Required]
      [MaxLength(200)]
      public string BrandName { get; set; }
      [Required]
      [MaxLength(200)]
      public string Color { get; set; }
      [Required]
      [MaxLength(200)]
      public string Size { get; set; }
  
      #region relations
  
      public virtual User.User User { get; set; }
      public virtual Product.Product Product { get; set; }
      public virtual ProductBrand ProductBrand { get; set; }
      public virtual ProductColor ProductColor { get; set; }
      public virtual ProductSize ProductSize { get; set; }
  
      #endregion
  }
  </code></pre>
  <p>This is Product class:</p>
  <pre><code>public class Product
  {
      public Product()
      {
  
      }
      [Key]
      public int ProductId { get; set; }
      public int CategoryId { get; set; }
      public int PB_Id { get; set; }
      public int PC_Id { get; set; }
      public int PS_Id { get; set; }
      public int Price { get; set; }
      public bool IsAvailable { get; set; }
      public string Name { get; set; }
      public string ShortDescription { get; set; }
      public string Description { get; set; }
      public string ImageName { get; set; }
      public DateTime? CreateDate { get; set; }
      public bool? IsDeleted { get; set; }
      public int? Visit { get; set; }
  
      #region relations
  
      public virtual Category Category { get; set; }
      public virtual ProductBrand ProductBrand { get; set; }
      public virtual ProductColor ProductColor { get; set; }
      public virtual ProductSize ProductSize { get; set; }
      public virtual List&lt;UserBasket&gt; UserBaskets { get; set; }
  
      #endregion
  }
  </code></pre>
  <p>This is the User class:</p>
  <pre><code> public class User
  {
      public User()
      {
          
      }
      [Key]
      public int UserId { get; set; }
      public string UserName { get; set; }
      public string Email { get; set; }
      public string Password { get; set; }
      public string ActiveCode { get; set; }
      public bool IsActive { get; set; }
      public DateTime? RegisterDate { get; set; }
      public bool? IsDeleted { get; set; }
  
      #region relations
      public virtual List&lt;UserBasket&gt; UserBaskets { get; set; }
      public virtual List&lt;UserOrder&gt; UserOrders { get; set; }
      #endregion
  }
  </code></pre>
  <p>when I run the project it shows</p>
  <blockquote>
  <p>System.NullReferenceException: 'Object reference not set to an instance of an object.'</p>
  </blockquote>
  <p>in view. What should I do?</p>