CodeFirst EF 4.1 : Changing Database Table and Column name

CodeFirst EF 4.1 : Changing Database Table and Column name

  • Comments 2

At times we need to control the Table and Column name of our generated database or have different Entity/Property name of code than actual database in EF 4.1 Code First. There are two ways we can do it.

Using Annotations

using System.ComponentModel.DataAnnotations;

    //Changing database Table name to Employee
    public class Emp
        //Changing database column name to EmpId
        public int Id { get; set; }
        public string Name { get; set; }

Using FluentAPI

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    //Changing Database Column name to EmployeeId
        .Property(p => p.Id)

    //Changing Database table name to EmployeeData
Note: If you have both Annotation and FluentAPI available, the FluentAPI will win.


Leave a Comment
  • Please add 3 and 1 and type the answer here:
  • Post
  • its really very nice & useful

  • I implemented it. But i'm not able to see the changed name reflected in the database. Are there any other steps we need to perform to get it reflected in database as well.

Page 1 of 1 (2 items)