Yadlapalli Srikanth

Yadlapalli Srikanth

  • NA
  • 272
  • 82.7k

mvc multiple tables in single context entity framework

Jun 27 2014 11:31 PM
Dear All,

I am learning Mvc, In db context i added one more dbset,it is working fine when it is with one dbset but when i added one more Dbset getting the below error.Kindly suggest me how to work with multiple tables with in one Dbcontext

public class EmployeeContext:DbContext
    {
      
        public DbSet<Employee> Employees { get; set; }
        public DbSet<Department> Departments { get; set; }
    }


error

An exception of type 'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code

Additional information: One or more validation errors were detected during model generation:



MVCP.Models.Department: : EntityType 'Department' has no key defined. Define the key for this EntityType.

Departments: EntityType: EntitySet 'Departments' is based on type 'Department' that has no keys defined.

Answers (3)