Cannot compare elements of type 'System.Linq.IQueryable`1'. Only primitive types, enumeration types and entity types are supported <p>i have this code in my controller</p> <pre><code>[HttpGet] public ActionResult Nabipour() { string name = "Nabipour"; var username = (from T in _db.tbl_teacher where T.Page==name select T.Username); ViewBag.Nabipour = from N in _db.tbl_Tpage where N.Username.Equals(username) select N; ViewBag.papers = from P in _db.tbl_Tpaper where P.Username.Equals(username) select P; return View(); } </code></pre> <p>and this is my view for this action:</p> <pre><code>@{ ViewBag.Title = "Nabipour"; Layout = "~/Views/Shared/_otherpage.cshtml"; } .... &lt;ul&gt; @foreach (var paper in ViewBag.papers) { &lt;li&gt;&lt;a href="~/Content/Paper/@paper.PaperName"&gt;&lt;/a&gt;&lt;/li&gt; } &lt;/ul&gt; .... </code></pre> <p>so as you see i not checking null in my select code and i tried this code with <code>.FirstOrDefault()</code> in the select. the error</p> <blockquote> <p>Cannot compare elements of type 'System.Linq.IQueryable 1 . Only primitive types, enumeration types and entity types are supported</p> </blockquote> <p>is on <code>@foreach (var paper in ViewBag.papers)</code> please help me what should i do? </p>