C# ASP.NET MVC序列不包含匹配元素

C# ASP.NET MVC序列不包含匹配元素,c#,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我是Asp.NETMVC新手。我几乎完成了我的项目,但项目中出现了一个奇怪的问题 当我尝试运行项目时,我收到错误消息 An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code Additional information: Sequence contains no matching element 在我的一个控

我是Asp.NETMVC新手。我几乎完成了我的项目,但项目中出现了一个奇怪的问题

当我尝试运行项目时,我收到错误消息

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

Additional information: Sequence contains no matching element
在我的一个控制器中,我使用下面的语句让所有组显示在dropdownlist中

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 => m.groupId), "groupId", "groupName");
或其他控制器:

ViewBag.CategoryDropDownValues = new SelectList(db.Category.OrderBy(m => m.categoryId), "categoryId", "categoryName");
所有使用此语法的控制器都会发生这种情况

我需要用数据库中的值显示DropDownList。直到早上,一切都正常工作。我不知道我在哪里改变了,它开始抛出这些错误

我已经尝试了中建议的其他解决方案,以便使用FirstOrDefault或SingleOrDefault

但一切都没有改变。我想我不是在选择一个值,而是一个值列表

请向正确的方向提出建议或指导,我们将对此表示感谢

-------编辑--------

@model App.Models.Policy

@using (Html.BeginForm("Search", "", FormMethod.Get, new { id = "search-form", @class = "form-horizontal" }))
{
<div class="span4 ">
   <div class="control-group">
       <label class="control-label" for="groupId">Group</label>
       <div class="controls">

      @Html.DropDownList("Group", (SelectList)@ViewBag.GroupDropDownValues, 
      "---Select Group ---", new { @class = "m-wrap span12" })

       </div>
   </div>
</div>
}

您是否尝试过.DefaultIfEmpty,这将使默认值为NULL,然后将执行group by,这可能会解决您的问题。谢谢您的评论。我像ViewBag.GroupDropDownValues=new SelectListdb.np\u groups.DefaultIfEmpty、group\u id、group\u name;这样尝试过;。但同样的问题。如果仔细观察DefaultIfEmpty,它会接受参数,如果为NULL,则该参数将用作默认值,例如,不,它不起作用:请为dropdownlist添加您的视图cod?