I create a model using EF and generated its context using DbContext 5.X generator. Now I renamed class name of one of my entities. Now when I run my code I get "The entity type Student2 is not part of the model for the current context." error.
var context = new MyEntities(connectionString);
foreach(var student in context.Students)
{
Console.WriteLine(class.Name.ToString());
}
In my data context.
public partial class MyEntities : DbContext
{
public MyEntities()
: base("name=MyEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
// public DbSet<Student> Students { get; set; } -> Origional
public DbSet<Student2> Student { get; set; } // I renamed Student to Student2
}
How to fix this? I need to rename my class due to some conflicts.
I had the same issue when i had wrong metadata in connection string. Try to recreate connection string in app.config.