user356178
user356178

Reputation:

EF5 : Manual table mapping

How to do manual table mapping in Entity Framework 5 using the Code First approach?

What I mean by table mapping is to associate a table name from the database to an entity class with a different name.

Upvotes: 1

Views: 1542

Answers (2)

chris vietor
chris vietor

Reputation: 2060

For fluent api:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<MyEntity>().ToTable("MyTargetTable");
    }

Upvotes: 2

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93424

This is pretty simple.

[Table("Foo")]
public class Bar {
      // properties
}

Upvotes: 2

Related Questions