title: Can not retrieve data from DB -> ERROR - >The entity or complex type ... cannot be constructed in a LINQ to Entities query
body: <p>I have checked majority of several question but unfortunately, due to lack of enought experience, will not be able to solve this problem without your help.</p>
  
  <p>I can not understand why this error happens. I think code is not wrong. </p>
  
  <p>To see whole code in <a href="https://github.com/TeymurovFuad/BookRental" rel="nofollow noreferrer">github</a></p>
  
  <p>This is</p>
  
  <blockquote>
    <p>UserController</p>
  </blockquote>
  
  <pre><code>using BookRental.Models;
  using BookRental.ViewModel;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Web;
  using System.Web.Mvc;
  
  namespace BookRental.Controllers
  {
      public class UserController : Controller
      {
  
          private ApplicationDbContext db;
  
          public UserController()
          {
              db = ApplicationDbContext.Create();
          }
  
  
  
          // GET: User/Index
          public ActionResult Index()
          {
              var userList = (from u in db.Users
                         join m in db.MembershipTypes on u.membershipTypeId equals m.membershipTypesIdPK
                         select new UserViewModel
                         {
                             Id = u.Id,
                             fname = u.fname,
                             lname = u.lname,
                             email = u.Email,
                             phone = u.phone,
                             bdate = u.bdate,
                             userMemTypeId = u.membershipTypeId,
                             MembershipTypes = (ICollection&lt;MembershipTypes&gt;)db.MembershipTypes.ToList().Where(n =&gt; n.membershipTypesIdPK.Equals(u.membershipTypeId)),
                             disabled = u.disabled
  
                         }).ToList();
  
              return View(userList);
          }
  </code></pre>
  
  <blockquote>
    <p>UserViewModel</p>
  </blockquote>
  
  <pre><code>using BookRental.Models;
  using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Web;
  
  namespace BookRental.ViewModel
  {
      public class UserViewModel
      {
          [Required]
          public string Id { get; set; }
  
          [Required]
          [DataType(DataType.EmailAddress)]
          public string email { get; set; }
  
          [DataType(DataType.Password)]
          public string password { get; set; }
  
          [DataType(DataType.Password)]
          public string confirmPassword { get; set; }
  
          public ICollection&lt;MembershipTypes&gt; MembershipTypes { get; set; }
  
          [Required]
          public int userMemTypeId { get; set; }
  
          [Required]
          public string fname { get; set; }
  
          [Required]
          public string lname { get; set; }
  
          [Required]
          public string phone { get; set; }
  
          [DataType(DataType.Date)]
          [DisplayFormat(DataFormatString = "{0:MM dd yyyy}")]
          public DateTime bdate { get; set; }
  
          public bool disabled { get; set; }
  
  
      }
  }
  </code></pre>
  
  <p>Index view</p>
  
  <pre><code>    @model IEnumerable&lt;BookRental.ViewModel.UserViewModel&gt;
  @using BookRental.Models
      @{
          ViewBag.Title = "Index";
      }
  
      &lt;h2&gt;Genre&lt;/h2&gt;
  
      @Html.Partial("_CreateButtonPartial")
  
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
  
      &lt;table class="table table-hover"&gt;
          &lt;thead class="thead-dark"&gt;
              &lt;tr class="row"&gt;
                  &lt;th class="col"&gt;
                      @Html.DisplayNameFor(m =&gt; m.fname)
                  &lt;/th&gt;
                  &lt;th class="col"&gt;
  
                      @Html.DisplayNameFor(m =&gt; m.lname)
                  &lt;/th&gt;
                  &lt;th class="col"&gt;
  
                      @Html.DisplayNameFor(m =&gt; m.email)
                  &lt;/th&gt;
                  &lt;th class="col"&gt;
  
                      @Html.DisplayNameFor(m =&gt; m.bdate)
                  &lt;/th&gt;
                  &lt;th class="col"&gt;
  
                      @Html.DisplayNameFor(m =&gt; m.phone)
                  &lt;/th&gt;
                  &lt;th class="col"&gt;
                      @Html.DisplayNameFor(m =&gt; m.disabled)
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              @foreach (var item in Model)
              {
                  &lt;tr class="row"&gt;
                      &lt;td class="col"&gt;
                          @Html.DisplayNameFor(item =&gt; item.fname)
                      &lt;/td&gt;
                      &lt;td class="col"&gt;
  
                          @Html.DisplayNameFor(item =&gt; item.lname)
                      &lt;/td&gt;
                      &lt;td class="col"&gt;
  
                          @Html.DisplayNameFor(item =&gt; item.email)
                      &lt;/td&gt;
                      &lt;td class="col"&gt;
  
                          @Html.DisplayNameFor(item =&gt; item.bdate)
                      &lt;/td&gt;
                      &lt;td class="col"&gt;
  
                          @Html.DisplayNameFor(item =&gt; item.phone)
                      &lt;/td&gt;
                      &lt;td class="col"&gt;
                          @Html.CheckBoxFor(m =&gt; item.disabled, new { @class = "disabled" })
                      &lt;/td&gt;
                      &lt;td class="col"&gt;
                          @Html.Partial("_TableButtonPartial", new IndividualButtonPartial { userId = item.Id})
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
          &lt;/tbody&gt;
      &lt;/table&gt;
  </code></pre>
  
  <blockquote>
    <p>Error</p>
  </blockquote>
  
  <pre><code>    System.NotSupportedException
    HResult=0x80131515
    Message=The entity or complex type 'BookRental.Models.UserViewModel' cannot be constructed in a LINQ to Entities query.
    Source=&lt;Cannot evaluate the exception source&gt;
    StackTrace:
  &lt;Cannot evaluate the exception stack trace&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AmK8F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AmK8F.png" alt="Error Screen"></a></p>