Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple object sets per type are not supported?

When I create the Scaffold for Controller and add the Model class then I am getting these error "Multiple object sets per type are not supported".

I have three Model class :

1.Department.CS

2.Designation.cs

3.CompanyDBContext.cs

Database : I have two table in database, 1. Department(deptID,deptName,Description) 2. Designation(desgtID,desgName,description)

Objective :- I want to create one view page for these scenario. Like this

Insert Name of Form (TextBox) + Department Name (Dropdown list box) + Designation Name (Dropdown list box)

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; }

  }
}

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; }
  }
}

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>();
      }
   }
 }
like image 509
Anurag Jain Avatar asked Jan 06 '14 17:01

Anurag Jain


1 Answers

You're creating your sets to be DbSet<CompanyDBContext>. What you want is DbSet<Department> and DbSet<Designation>.

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

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

This seems pretty clearly to be a typo, but the reason you're getting the error is because the runtime wouldn't know how to populate multiple object sets on the same context that have the same element type. This would be more like saying:

public DbSet<Department> SomeDepartments { get; set; }
public DbSet<Department> OtherDepartments { get; set; }

Since (presumably) you would expect something to define what would be in SomeDepartments and there would be something to define what's in OtherDepartments and the runtime doesn't know this (and there's no way to express it), that's why you're getting the error.

like image 86
Adam Robinson Avatar answered Oct 27 '22 04:10

Adam Robinson