【发布时间】:2011-09-04 12:24:43
【问题描述】:
这个问题是从以下继续: Can't think of query that solves this many to many
这个 LINQ 查询是用户 @juharr 推荐给我的,我只是添加了字符串连接,目的是将名字和姓氏组合成全名。
var courseViews = from c in db.Courses 选择新的 CourseView() { CourseID = c.ID, ProfessorName =(来自 c.Leturers 中的 l l.Is_Professor 在哪里 选择 l.LastName+" "+l.FirstName).FirstOrDefault(), AssistantNames =(来自 c.Leturers 中的 l 在哪里!l.Is_Professor 选择 l.LastName+" "+l.FirstName) .ToList() //hmmm 问题 };我使用的 ModelView 是另一个可能的问题原因:
公开课 CourseView { 公共 int ID { 获取;放; } 公共字符串 CourseName { 获取;放; } 公共字符串教授姓名{得到;放; } 公共列表 AssistantNames { get;放; } }嗯,助手名称的字符串列表有问题不是吗?
在我的愚蠢结束时,在 View 中,我用@foreach(var s in item.AssistantNames){@s}循环浏览了这个列表
@Ladislav 建议使用 IQueryable 而不是字符串,如何在哪里?
对于我到目前为止所做的解决方案,我得到以下 错误:
LINQ to Entities 无法识别方法 'System.Collections.Generic.List1[System.String] ToList[String](System.Collections.Generic.IEnumerable1[System.String])' 方法,并且此方法无法转换为存储表达式。
需要帮助!
【问题讨论】:
-
public List AssistantNames { get; set; }可能是public List<string> AssistantNames { get; set; }
标签: c# entity-framework asp.net-mvc-3