How to map table names and column name different from model in onmodelcreating method in Entity Framework -6?

走远了吗. 提交于 2019-12-04 02:15:58

If you are using Code First, you can simply decorate your model with Table and Column attribute and give it the database names.

[Table("tbl_Student")]
public class Student
{
    [Column("u_id")]
    public int ID { get; set; }
}

These attributes are available in the System.ComponentModel.DataAnnotations.Schema namespace

You can keep following inside OnModelCreating

modelBuilder.Entity<MyModel>()
.Property(e => e.MyColumn).HasColumnName("DBColumn")

And if you're not using code-first, just select a table in the model diagram, hit F4 (properties) and change the name.

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