Asp.net mvc 3 使用t4脚手架获取mvc4中模型(TableName)的元数据
使用MVC4和T4模板(脚手架) 我正在mvc4中创建一个模型,并在DBContext中指定表名。 1) 我需要根据模型名从Dbcontext获取表。 2) 需要从注释表中获取值Asp.net mvc 3 使用t4脚手架获取mvc4中模型(TableName)的元数据,asp.net-mvc-3,asp.net-mvc-4,t4,asp.net-mvc-3-areas,asp.net-mvc-scaffolding,Asp.net Mvc 3,Asp.net Mvc 4,T4,Asp.net Mvc 3 Areas,Asp.net Mvc 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
[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(新的AssemblyName(Convert.ToString(objFile))).CreateInstance(namespaceInstance)
如何在不使用dll的情况下根据t4模板中的模型名获取表名,我们使用ModelProperty类。
请提出建议。虽然这并不能完全回答您的问题,但它提供了另一种加载程序集的方法,使其不会锁定 如果问题不清楚,请询问。
var attributeData = objMaster.GetType().GetCustomAttributesData().Select(p => p.ConstructorArguments).ToArray();
var tableNameVariable= attributeData[0][0].Value.ToString();