Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.net MVC 5无法检索的元数据_C#_Asp.net_Asp.net Mvc_Entity Framework_Asp.net Mvc 5 - Fatal编程技术网

C# ASP.net MVC 5无法检索的元数据

C# ASP.net MVC 5无法检索的元数据,c#,asp.net,asp.net-mvc,entity-framework,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc,Entity Framework,Asp.net Mvc 5,我是ASP.NETMVC5新手,我正在使用entityframework创建一个网站。我有两个表Employee和Department。现在,当我创建一个名为DepartmentMembers的模型时,在我的控制器EmployeeController中创建一个方法后,它将获得一个值部门名称和成员数,这是我的代码 public ActionResult DepartmentCount() { var employees = db.Employees.Include(e =&

我是ASP.NETMVC5新手,我正在使用entityframework创建一个网站。我有两个表
Employee
Department
。现在,当我创建一个名为
DepartmentMembers
的模型时,在我的控制器
EmployeeController
中创建一个方法后,它将获得一个值
部门名称
成员数
,这是我的代码

public ActionResult DepartmentCount()
    {
        var employees = db.Employees.Include(e => e.Department)
            .GroupBy(d => d.Department.Department_Name).Select(c => new DepartmentMembers
            {
                DepartmentName = c.Key,
                MemberTotal = c.Count()
            }).ToList().OrderByDescending(o => o.MemberTotal);
        return View(employees.ToList());
    }
现在,当我试图添加一个带有模板
List
和数据上下文类作为连接字符串的视图时,我遇到了这个错误

MVC似乎假设my class
DepartmentMembers
也是一个表。我怎样才能做到这一点

编辑1:这是我的部门成员课程

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVCusingEntityFramework.Models
{
[NotMapped]
public class DepartmentMembers
{
    public string DepartmentName { get; set; }
    public int MemberTotal { get; set; }
}
}
添加
[NotMapped]
属性后,由于该类未映射到我的表中,因此错误消息显示


你能把你的
部门成员
课程发出去吗?@PranavPatel我刚发了,请检查一下。我认为我的连接没有问题。但你认为我应该提供它吗?我在你的模型中看不到任何PK,在实体框架中,每个模型都需要一个主键。请参考,并让我知道如果你仍然得到error@PranavPatel添加
[NotMapped]
属性后(因为它未映射到我的数据库或表中),我遇到了另一个错误。请阅读我的编辑。您是否已向DbContext注册您的类?