Search code examples
asp.net-mvc-3asp.net-mvc-4t4asp.net-mvc-scaffolding

Get The Table Name Of Model In T4 Template


I am using MVC4 ,T4 Scaffolding and EF5. I Created a model,

namespace wbtest.Models
{
[Table(name: "Pay_Employees_Mst", Schema = "Test")]
public class Employee
 {
public int EMPLOYEE_ID { get; set; }
public string EMPLOYEE_CODE { get; set; }
}
}

I need to get the annotation of table name "Pay_Employees_Mst" for db context .Currently getting ModelName Employee.

Please Help.


Solution

  • I got it through,

    String entityName1 = (context as System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext
      .CreateObjectSet<Employee>()
      .EntitySet.Name;