I have 2 classes Foo and Bar
public class Foo
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int Id { get; set; }
private ICollection<Bar> _bar;
public virtual ICollection<Bar> Bars
{
get { return _bar?? (_bar= new Collection<Bar>()); }
set { _bar= value; }
}
}
Bar
public class Bar
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int Id { get; set; }
private ICollection<Foo> _foo1;
public virtual ICollection<Foo> Foos1
{
get { return _foo1?? (_foo1= new Collection<Foo>()); }
set { _foo1= value; }
}
private ICollection<Foo> _foo2;
public virtual ICollection<Foo> Foos2
{
get { return _foo2?? (_foo2= new Collection<Foo>()); }
set { _foo2= value; }
}
}
I then use Migration to update the database. However, instead of having an usual table FooBar. EF creates 2 tables
Foo
Id,Bar_Id
Bar
Id,Foo_Id,Foo_Id1
which is not what I want. I guess I'm messing up by adding 2 collections of Foo into Bar. What should I do now?