Entity Framework の使用: コード まず、基本クラスのナビゲーション プロパティを使用してコレクション ナビゲーション プロパティを定義しようとしています。
オブジェクト構造:
public class Content
{
public int ID { get; set; }
public ModerationStatuses ModerationStatus { get; set; }
public ContentItemTypes ContentType { get; set; }
public virtual User Author { get; set; }
}
public class Image : Content
{
public Image()
: base()
{
ContentType = ContentItemTypes.Image;
}
public string FileName { get; set; }
public string Location { get; set; }
public int DisplayOrder { get; set; }
public long FileSize { get; set; }
}
public class User
{
public int UserID { get; set; }
public string Username { get; set; }
public virtual ICollection<Image> Images { get; set; }
}
コンテキスト OnModelCreating:
modelBuilder.Entity<Content>()
.Map(i => i.ToTable("Content"));
modelBuilder.Entity<Image>()
.Map(i => i.ToTable("Images"));
データベースが生成されると、Content テーブルで Author_UserID を使用する代わりに、Images テーブルに User_UserID 外部キー制約が作成されます。
ICollection<Image>
Content..Author_UserID フィールドをナビゲーション プロパティの外部キーとして認識させるにはどうすればよいですか?