簡體   English   中英

使用t4 Scaffolding在mvc4中獲取模型(TableName)的元數據

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM