获取元数据模型(TableName)在mvc4使用t4脚手架



使用MVC4和T4模板(脚手架)我正在mvc4中创建一个模型,并在DBContext中指定表名。1)我需要从Dbcontext获得表对模型名称。2)需要从注释表中获取值

[Table(name: "Pay_Emp_Qualifications", Schema = "Sample")]
public class EmpQualification
{
    [Key]
    public int EMP_QUALI_ID { get; set; }
    public String Qualification { get; set; }
}

目前我们得到加载dll对模型和使用反射我们得到。我们正在尝试避免此dll

var  objFile= Assembly.LoadFile(@"binwbtest.dll");

var objMaster = AppDomain.CurrentDomain。负载(新AssemblyName (Convert.ToString (objFile))) .CreateInstance (namespaceInstance);

 var attributeData = objMaster.GetType().GetCustomAttributesData().Select(p =>           p.ConstructorArguments).ToArray();
           var tableNameVariable= attributeData[0][0].Value.ToString();

如何在不使用dll的情况下在t4模板中获得表名和模型名,我们使用ModelProperty类。请建议。

虽然这并不能完全回答您的问题,但它为您提供了另一种加载程序集的方法,使其不会被锁定。T4和MSBuild集成问题

最新更新