简体   繁体   English

使用t4 Scaffolding在mvc4中获取模型(TableName)的元数据

[英]Get metadata of model (TableName) in mvc4 Using t4 Scaffolding

Using MVC4 and T4 Template(Scaffolding) I am creating a model in mvc4 and specify the table name in DBContext. 使用MVC4和T4模板(脚手架)我在mvc4中创建一个模型,并在DBContext中指定表名。 1)I need to get the table from Dbcontext against model name. 1)我需要从模型名称获取Dbcontext的表。 2)Need to get value from annotation Table. 2)需要从注释表中获取值。

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

Currently we getting load the dll against the model and using reflection we get.We are trying to avoid this dll 目前我们正在对模型加载dll并使用我们得到的反射。我们试图避免这个dll

var  objFile= Assembly.LoadFile(@"bin\wbtest.dll");

var objMaster = AppDomain.CurrentDomain.Load(new AssemblyName(Convert.ToString(objFile))).CreateInstance(namespaceInstance); var objMaster = AppDomain.CurrentDomain.Load(new AssemblyName(Convert.ToString(objFile)))。CreateInstance(namespaceInstance);

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

How to get table name against model name in t4 template without using dll,we using ModelProperty class. 如何在不使用dll的情况下在t4模板中获取模型名称的表名,我们使用ModelProperty类。 Please Suggest. 请建议。

While this doesn't exactly answer your question, it gives you an alternative way of loading the assembly so that it doesn't lock it. 虽然这不能完全回答您的问题,但它为您提供了另一种加载程序集的方法,使其不会锁定它。 T4 and MSBuild integration issues T4和MSBuild集成问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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