【发布时间】:2013-05-02 13:53:08
【问题描述】:
使用 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 类。 请提出建议。
【问题讨论】:
-
如果问题不清楚请追问。
标签: asp.net-mvc-3 asp.net-mvc-4 t4 asp.net-mvc-3-areas asp.net-mvc-scaffolding