不支持每种类型的多个对象集?

Anu*_*ain 5 c# asp.net visual-studio-2013 asp.net-mvc-5

当我为Controller创建Scaffold并添加Model类时,我收到这些错误" 不支持每种类型的多个对象集 ".

我有三个Model类:

1.Department.CS

2.Designation.cs

3.CompanyDBContext.cs

数据库:我在数据库中有两个表,1.部门(deptID,deptName,描述)2.指定(desgtID,desgName,description)

目标: - 我想为这些场景创建一个视图页面.像这样

插入表格名称(TextBox)+部门名称(下拉列表框)+名称名称(下拉列表框)

1.Department.CS

namespace mvcAppraisalSystem.Models
{
  public class Department
  {
        [Key]
        public int deptID { get; set; }
        public string deptName { get; set; }
        public string Description { get; set; }

  }
}
Run Code Online (Sandbox Code Playgroud)

2.Designation.cs

 namespace mvcAppraisalSystem.Models
{
   public class Designation
  {
    [Key]
    public int desgID { get; set; }
    public string desgName { get; set; }
    public string description { get; set; }
  }
}
Run Code Online (Sandbox Code Playgroud)

3.CompanyDBContext.cs

  namespace mvcAppraisalSystem.Models
 {
    public class CompanyDBContext : DbContext
   {
       public CompanyDBContext() : base("CompanyDBContext")
       {


       }
       public DbSet<CompanyDBContext> Departments { get; set; }

       public DbSet<CompanyDBContext> Designations { get; set; }

       protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
      }
   }
 }
Run Code Online (Sandbox Code Playgroud)

Ada*_*son 14

你正在创建你的集合DbSet<CompanyDBContext>.你想要的是DbSet<Department>DbSet<Designation>.

   public DbSet<Department> Departments { get; set; }

   public DbSet<Designation> Designations { get; set; }
Run Code Online (Sandbox Code Playgroud)

这似乎很明显是一个错字,但是你得到错误的原因是因为运行时不知道如何在具有相同元素类型的相同上下文中填充多个对象集.这更像是在说:

public DbSet<Department> SomeDepartments { get; set; }
public DbSet<Department> OtherDepartments { get; set; }
Run Code Online (Sandbox Code Playgroud)

因为(大概)你会期望有什么东西可以定义什么,SomeDepartments并且会有东西来定义什么OtherDepartments,运行时不知道这个(并且没有办法表达它),这就是你得到错误的原因.