EF5 : Manual table mapping

强颜欢笑 提交于 2019-12-08 05:20:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!