C# 实体类型Employee不是当前上下文模型的一部分
我正面临这个问题,我通过几个帖子,请回复我如何解决这个问题。 下面是我的代码 控制器类C# 实体类型Employee不是当前上下文模型的一部分,c#,asp.net-mvc,entity-framework,C#,Asp.net Mvc,Entity Framework,我正面临这个问题,我通过几个帖子,请回复我如何解决这个问题。 下面是我的代码 控制器类 public class EmployeeContext : DbContext { public DbSet<Employee> Employees { get; set; } } namespace MvcApplication6.Models { [Table("tblEmployee")] public class Employee {
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
namespace MvcApplication6.Models
{
[Table("tblEmployee")]
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
}
}
在第三行中,我得到错误“实体类型Employee不是当前上下文模型的一部分”
EmployeeContext类
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
namespace MvcApplication6.Models
{
[Table("tblEmployee")]
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
}
}
实体数据模型名称Employee.edmx发生此情况的原因可能是:
配置的连接字符串不正确DbContext
- 指定的实体实际上未在
配置中映射
[Table(“tblEmployee”)]
属性,它是否有效?您可以共享您的edmx文件吗?我删除了[Table(“tblEmployee”)]属性仍然是相同的错误edmx文件具有Id、名称、性别、城市列的员工表您在视图中对该实体做了什么?显示表数据,即Id、名称、性别、城市值简直像个符咒!