I have two objects in which one is related to each other. Example:
public class Question
{
public int Id { get; set; }
public string Text { get; set; }
public Answer[] Answers { get; set; }
}
public class Answer
{
public int Id {get; set; }
public string Text { get; set; }
}
Using EF6 Code First, I installed this simple DbContext:
public class MyContext : DbContext
{
public MyContext()
{
Database.SetInitializer<MyContext>(new DropCreateDatabaseAlways<MyContext>());
}
public DbSet<Question> Questions { get; set; }
public DbSet<Answer> Answers { get; set; }
}
What I get in the database are two similarly structured tables (int PK column and varchar column), and there is no representation of the “one question has many answers” relationship that I intended to use with the Question.Answers property.
Why doesn't the EF code first display the relationship and how can I fix it?
source
share