3

MVC4 と T4 Template(Scaffolding) を使用して、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クラスを使用します。提案してください。

4

1 に答える 1

0

これはあなたの質問に正確に答えるものではありませんが、アセンブリをロックしないようにアセンブリをロードする別の方法を提供します。 T4 と MSBuild の統合の問題

于 2013-09-29T15:19:54.950 に答える