简体   繁体   中英

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.

I got it through,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM