Do you create a separate context for each of the classes?
public class Employee { [Key] public int EmpId { get; set; }
And then listing all your models in context:
public MyDbContext : DbContext { public DbSet<Employee> Employees { get; set; } public DbSet<AnotherClass> AnotherClasses { get; set; } }
You can also specify the name of the connection string using the constructor in the Context:
public MyDbContext() : base("ConnectionString") { }
It is important that all your models are in the same context.
Use of context
var context = new MyDbContext(); var employees = context.employees.ToList();
This tells EF to query the database and store the data inside the employee variable.
source share