EF5 : Manual table mapping

2019-06-07 01:48发布

问题:

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.

回答1:

This is pretty simple.

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


回答2:

For fluent api:

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