问题
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");
}
来源:https://stackoverflow.com/questions/12957991/ef5-manual-table-mapping