私は、他のテーブルとの一対多のリレーションシップを持つテーブルを持つ EF コード ファースト モデルを持っています。
public class Note
{
[Key]
public Guid Id { get; set; }
public string NoteText { get; set; }
public string Author { get; set; }
public DateTime? CreationDate { get; set; }
}
public class Foo
{
public Foo()
{
Notes = new HashSet<Note>();
}
[Key]
public Guid Id { get; set; }
public virtual ICollection<Note> Notes { get; set; }
// other properties ommited...
}
public class Bar
{
public Bar()
{
Notes = new HashSet<Note>();
}
[Key]
public Guid Id { get; set; }
public virtual ICollection<Note> Notes { get; set; }
// other properties ommited...
}
ご覧のとおり、 と の両方FooにBarの独自のリストがありますNotesが、 aは aまたはa のNoteいずれかに属します。Foo Bar
移行をスキャフォールディングするとき、EF は と の外部キーをテーブルに作成しFooますBarがNotes、これは正しくないと思います。代わりに、 と の間にリンク テーブルを作成し、 と の間FooにNotes別のリンク テーブルを作成したいBarと思いNotesます。
これを自動的に行う方法はありますか?または、コード ファーストの実装でこれらのクラスを手動で作成する必要がありますか?