如果DetailDescription只是viewmodel中的一个字符串,而不是IList,那么我猜它是一个ProjectDetailViewModel,所以您的linq应该是:
var result = _dbContext.ProjectDetails //<==search from details
.Select(x => new ProjectDetailViewModel
{
projectTypeId = x.Project.ProjectTypeId,
projectType = x.Project.projectType,
DetailDescription = x.DetailDescription,
AnswerDescription = x.ProjectDetailsAnswers.Select(a => a.AnswerDescription)
}).ToList();
但如果你坚持从项目中查询:
var result = _dbContext.Projects.SelectMany(x=>x.ProjectDetails) //<==use SelectMany
.Select(x => new ProjectDetailViewModel
{
projectTypeId = x.Project.ProjectTypeId,
projectType = x.Project.projectType,
DetailDescription = x.DetailDescription,
AnswerDescription = x.ProjectDetailsAnswers.Select(a => a.AnswerDescription)
}).ToList();