[英]Get metadata of model (TableName) in mvc4 Using t4 Scaffolding
使用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(@"bin\wbtest.dll");
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();
如何在不使用dll的情况下在t4模板中获取模型名称的表名,我们使用ModelProperty类。 请建议。
虽然这不能完全回答您的问题,但它为您提供了另一种加载程序集的方法,使其不会锁定它。 T4和MSBuild集成问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.