I am using Entity Framework 5 and I have these classes:
public partial class Subject
{
public int SubjectId { get; set; }
public string Name { get; set; }
public virtual ICollection<Topic> Topics { get; set; }
}
public partial class Topic
{
public int TopicId { get; set; }
public string Name { get; set; }
public int SubjectId { get; set; }
public virtual Subject Subject { get; set; }
public virtual ICollection<SubTopic> SubTopics { get; set; }
}
public partial class SubTopic
{
public int SubTopicId { get; set; }
public string Name { get; set; }
public int TopicId { get; set; }
public virtual Topic Topic { get; set; }
}
Now I am trying to write a LINQ query to populate this class:
public class TopicSubTopicSelect
{
public int TopicId { get; set; }
public int SubTopicId { get; set; }
public string TopicName { get; set; }
public string SubTopicName { get; set; }
}
So far I have this:
return _subjectsRepository
.GetAll()
.Where(s => s.SubjectId == subjectId)
.Include(s => s.Topics)
.Include(s => s.Topics.) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.AsEnumerable()
.Select(item => new TopicSubTopicSelect(item.TopicId,
item.SubTopicId,
item.Topic.Name,
item.Name))
.ToList();
But it gives me an error on the line where I put <<<<<
What I wanted was to have .Include(s => s.Topics.SubTopics)
However intellisense does not give me this as an option. Any ideas what I am doing wrong and how I can modify the LINQ to get the data to fill the TopicSubTopicSelect class