Fernando
Fernando

Reputation: 1249

Entity Framework Table Name Change

I have a table named X that is already mapped to my Entity Model. I want to change the name of the table to Y in the database and Y in my entity model.

What is the easiest way to do this?

Is the best thing to delete the

Upvotes: 0

Views: 1481

Answers (2)

noobob
noobob

Reputation: 532

A solution would be to override a method in your DbContext class, based on the database you are connecting too.

public class YourDbContext : DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Product>().ToTable("yourNewTableName");
    }
}

Upvotes: 1

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93434

Delete the?

If you eman entity, then yes. Assuming you're using database first approach, and your model does not require a lot of reconfiguration. then update the model from db, and you're good.

Upvotes: 0

Related Questions