【问题标题】:Get metadata of model (TableName) in mvc4 Using t4 Scaffolding使用 t4 Scaffolding 在 mvc4 中获取模型(TableName)的元数据
【发布时间】: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


【解决方案1】:

虽然这不能完全回答您的问题,但它为您提供了另一种加载程序集的方法,这样它就不会锁定它。 T4 and MSBuild integration issues

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    相关资源
    最近更新 更多