title: Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[]' using linq lambda expression
body: <p>i'm new to mvc and trying to get idea of what i'm doing wrong i create a <code>Dbcontaxt</code> class</p>
  
  <pre><code> public class DataBaseContext : DbContext
  {
      public DataBaseContext()
          : base("DefaultConnection")
      {
      }
      public DbSet&lt;Membership&gt; Membership { get; set; }
      public DbSet&lt;OAuthMembership&gt; OAuthMembership { get; set; }
      public DbSet&lt;Role&gt; Roles { get; set; }
      public DbSet&lt;UserProfile&gt; UserProfiles { get; set; }
      public DbSet&lt;Category&gt; Categorys { get; set; }
      public DbSet&lt;SubCategory&gt; SubCategorys { get; set; }
      public DbSet&lt;Product&gt; Products { get; set; }
      public DbSet&lt;Color&gt; Colors { get; set; }
      public DbSet&lt;Size&gt; Sizes { get; set; }
      public DbSet&lt;Company&gt; Companys { get; set; }
      public DbSet&lt;UsersInRoles&gt; UsersInRoles { get; set; }
    }
  }
  </code></pre>
  
  <p>and i create a model class to create a strongly type view </p>
  
  <pre><code>    [Bind(Exclude = "AddUserToRoleID")]
      public class AddUserToRole
  {
      [ScaffoldColumn(false)]
      public int AddUserToRoleID { get; set; }
      [Required]
      [Display(Name = "User name")]
      public string UserName { get; set; }
      [Required]
      [Display(Name = "Role name")]
      public string RoleName { get; set; }
  
  }
  }
  </code></pre>
  
  <p>in the controller i'm trying to create the Details view by adding view and select <code>AddUserToRole</code> as my model for the strongly type view </p>
  
  <pre><code>    public ActionResult Details(int id = 0)
      {
  
          var UserInRole = db.UserProfiles
          .Join(db.UsersInRoles,
                u =&gt; u.UserId,
                uir =&gt; uir.UserId,
                (u, uir) =&gt; new {u = u,uir = uir})
          .Join(db.Roles,
                temp0 =&gt; temp0.uir.RoleId,
                r =&gt; r.RoleId,
                (temp0, r) =&gt; new { temp0 = temp0,r = r })
          .Where(temp1 =&gt; (temp1.temp0.u.UserId == id))
          .Select(temp1 =&gt; new AddUserToRole {
              AddUserToRoleID = temp1.temp0.u.UserId,
              UserName = temp1.temp0.u.UserName,
              RoleName = temp1.r.RoleName
          });            
  
          return View(UserInRole);
      }
  </code></pre>
  
  <p>it give me this error </p>
  
  <pre><code>The model item passed into the dictionary is of type
  'System.Data.Entity.Infrastructure.DbQuery`1[SeniorProject.Models.AddUserToRole]', but
  this dictionary requires a model item of type 'SeniorProject.Models.AddUserToRole'.
  </code></pre>
  
  <p>and when i cast <code>return View((UsersInRoles)UserInRole);</code> it give me this error </p>
  
  <pre><code>Unable to cast object of type
  'System.Data.Entity.Infrastructure.DbQuery`1[SeniorProject.Models.AddUserToRole]' 
   to type'SeniorProject.Models.UsersInRoles'.
  </code></pre>
  
  <p>and the view </p>
  
  <pre><code>@model SeniorProject.Models.AddUserToRole
  
  @{
  ViewBag.Title = "Details";
  }
  
  &lt;h2&gt;Details&lt;/h2&gt;
  
  &lt;fieldset&gt;
      &lt;legend&gt;AddUserToRole&lt;/legend&gt;
  
  &lt;div class="display-label"&gt;
       @Html.DisplayNameFor(model =&gt; model.UserName)
  &lt;/div&gt;
  &lt;div class="display-field"&gt;
      @Html.DisplayFor(model =&gt; model.UserName)
  &lt;/div&gt;
  
  &lt;div class="display-label"&gt;
       @Html.DisplayNameFor(model =&gt; model.RoleName)
  &lt;/div&gt;
  &lt;div class="display-field"&gt;
      @Html.DisplayFor(model =&gt; model.RoleName)
  &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;p&gt;
  @Html.ActionLink("Edit", "Edit", new { id=Model.AddUserToRoleID }) |
  @Html.ActionLink("Back to List", "Index")
  &lt;/p&gt;
  </code></pre>
  
  <p>what should i do in this case?</p>