I have a project that was running with .net core 3.1. After upgrading to .net 5 and entity framework core to 5.0.3, the include is not working anymore.
I have these classes
public class Question
{
[Key]
public Guid Id { get; set; }
public string QuestionCode { get; set; }
[ForeignKey("AnswersId")]
public Answer Answers { get; set; }
}
public class Answer
{
[Key]
public Guid Id { get; set; }
public string Answers { get; set; }
public int Score { get; set; }
}
The relation is defined as follows:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Question>()
.HasOne(q => q.Answers);
}
and this simple LINQ:
return _context.Questions
.Include(q => q.Answers)
.FirstOrDefault(s => s.Id == id);
however. the include is not working after the version upgrade. By not working i mean the returned values doesn't include Answers. Main entity only is returned and all the fields in the child are null.