親列と子列に、Element_IDとElement_ID1ではなく、より意味のある名前を付けようとしています。
Elementテーブルは問題なく生成されますが、2番目のテーブルは列名を更新したいものです。
[Column("ParentID")]
親プロパティの減速の上に属性を追加しようとしましたが、生成されたテーブルには影響しません。
エンティティクラス
public class Element
{
public Guid ID { get; set; }
public string Title { get; set; }
public int Status { get; set; }
public virtual List<Element> Parent { get; set; }
public virtual List<Element> Child { get; set; }
}
生成された移行
CreateTable(
"dbo.ElementElements",
c => new
{
Element_ID = c.Guid(nullable: false),
Element_ID1 = c.Guid(nullable: false),
})
.PrimaryKey(t => new { t.Element_ID, t.Element_ID1 })
.ForeignKey("dbo.Elements", t => t.Element_ID)
.ForeignKey("dbo.Elements", t => t.Element_ID1)
.Index(t => t.Element_ID)
.Index(t => t.Element_ID1);
2番目のエンティティをそのまま使用すると、2番目のテーブルを必要に応じて出力できます
public class Hierarchy
{
public Guid ID { get; set; }
public virtual Guid ParentID { get; set; }
public virtual Element Parent { get; set; }
public virtual Guid ChildID { get; set; }
public virtual Element Child { get; set; }
}
次の作成スクリプトを生成しました
CreateTable(
"dbo.Hierarchies",
c => new
{
ID = c.Guid(nullable: false),
ParentID = c.Guid(nullable: false),
ChildID = c.Guid(nullable: false),
})
.PrimaryKey(t => t.ID)
.ForeignKey("dbo.Elements", t => t.ParentID)
.ForeignKey("dbo.Elements", t => t.ChildID)
.Index(t => t.ParentID)
.Index(t => t.ChildID);
では、1つのエンティティクラスだけで必要な列名を使用して2番目のテーブルを生成することは可能ですか?