我有这两个类:
public partial class Topic {
public int TopicId { get; set; }
public string Name { 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;
}
这是我当前的 LINQ 语句:
var subTopics = _subTopicsRepository
.GetAll()
.Where(s => s.TopicId == topicId)
.ToList();
我怎样才能使 subTopics 变量也具有 TopicId 和 Topic.Name ,然后让它填充视图:
public partial class TopicSubTopic
{
public int TopicId { get; set; }
public int SubTopicId { get; set; }
public string TopicName { get; set; }
public string SubtopicName { get; set; }
}