title: ASP.NET MVC Sequence contains no matching element
body: <p>I am new to Asp.Net MVc. I have almost finished my project but a strange issue appeared in project.</p>
  
  <p>As I try to run the project I get Error message.</p>
  
  <pre><code>An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
  
  Additional information: Sequence contains no matching element
  </code></pre>
  
  <p>In one of my controller I am using the statement below to get all groups to display in a dropdownlist.</p>
  
  <pre><code>http://localhost....../Clients (trying to run this page) and getting error on the line containing code below.
  
   ViewBag.GroupDropDownValues   = new SelectList(db.Groups.OrderBy(m =&gt; m.groupId), "groupId", "groupName");
  </code></pre>
  
  <p>Or the other controller:</p>
  
  <pre><code>ViewBag.CategoryDropDownValues = new SelectList(db.Category.OrderBy(m =&gt; m.categoryId), "categoryId", "categoryName");
  </code></pre>
  
  <p>This happening in all the controllers that are using this syntax.</p>
  
  <p>I need to display dropdownLists with values from database. Everything was working correctly till morning. I don't have idea where I changed and it started throwing these  errors.</p>
  
  <p>I have already tried other solutions suggested in SO to use <code>FirstOrDefault</code> or <code>SingleOrDefault</code></p>
  
  <p>like <a href="https://stackoverflow.com/questions/16526294/sequence-contains-no-elements-error-with-inheritance?rq=1">Sequence contains no elements error with inheritance</a></p>
  
  <p>but nothing changed. I think I am not selecting a single value but a list of values.</p>
  
  <p>Please suggest something or guide in right direction as will be thankful. </p>
  
  <p>------------- Edit ---------------</p>
  
  <pre><code>@model App.Models.Policy
  
  @using (Html.BeginForm("Search", "", FormMethod.Get, new { id = "search-form", @class = "form-horizontal" }))
  {
  &lt;div class="span4 "&gt;
     &lt;div class="control-group"&gt;
         &lt;label class="control-label" for="groupId"&gt;Group&lt;/label&gt;
         &lt;div class="controls"&gt;
  
        @Html.DropDownList("Group", (SelectList)@ViewBag.GroupDropDownValues, 
        "---Select Group ---", new { @class = "m-wrap span12" })
  
         &lt;/div&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  }
  </code></pre>