DbExpressionBinding需要在ASP.NET MVC中使用集合ResultType的输入表达式

时间:2014-08-22 18:23:35

标签: c# asp.net-mvc entity-framework

我收到此错误DbExpressionBinding需要一个带有ResultType集合的输入表达式。在使用ASP.NET MVC时仍然非常绿色,所以我不了解发生了什么以及为什么我收到此错误。淘网论坛,但没有什么是真正有意义的。使用ADO.Net实体模型。实体框架6。

控制器

readonly StatsEntity1 _db = new StatsEntity1();

public ActionResult Index()
{
    var statsC = (from n in _db.WKLY_STATSTC
                  where n.TERM == "14"&& n.GRP=="C"
                  select n.TERM into w
                  select new { Count = w.Count() });

    var statsN = (from n in _db.WKLY_STATSTC
                  where n.TERM == "14" && n.GRP == "N"
                  select n.TERM into w
                  select new { Count = w.Count() });

    ViewBag.StatsC = statsC;
    ViewBag.StatsN = statsN;
    return View("Index");
}

查看

@model IEnumerable<Reports.Models.WKLY_STATSTC>
<table>
    <tr>
        <td>@ViewBag.StatsC</td>
        <td>@ViewBag.StatsN</td>
    </tr>
</table>

1 个答案:

答案 0 :(得分:3)

您可能需要的是获取查询的计数。

       var statsC = (from n in _db.WKLY_STATSTC
                    where n.TERM == "14" &&
                            n.GRP == "C"
                    select n.TERM).Count();

        var statsN = (from n in _db.WKLY_STATSTC
                     where n.TERM == "14" &&
                             n.GRP == "N"
                     select n.TERM).Count();

除非你需要的是n.Term长度的真实数组。

       var statsC = (from n in _db.WKLY_STATSTC
                    where n.TERM == "14" &&
                            n.GRP == "C"
                    select n.TERM into w

                    select new { Count = w.Length }).ToArray();

        var statsN = (from n in _db.WKLY_STATSTC
                     where n.TERM == "14" &&
                             n.GRP == "N"
                     select n.TERM into w

                     select new { Count = w.Length }).ToArray();