I am afraid to create simple one-to-many relationships using Code First in EF. I want him to create a database for me, but he could not understand how to write these classes in order to create it.
I have the following classes:
public class Book
{
public int ID { get; set; }
public string Author { get; set; }
public ICollection<Page> Pages { get; set; }
}
public class Page
{ [Key]
public int BookID { get; set; }
public Book Book { get; set; }
public string OtherField { get; set; }
}
But I get an error while it binds to generate the database:
The main end of the relationship between the types "MvcApplication1.Models.Page" and "MvcApplication1.Models.Book" cannot be determined. The main end of this association must be explicitly configured using a free API or data annotation
: "" BookID . , .