【发布时间】:2014-09-10 19:29:14
【问题描述】:
我正在尝试使用 linq 查询数据,我正在加入两个表,其中 id == 到第二个表的 id。我收到一个异常错误提示
不能隐式转换类型 '
System.Collections.Generic.List<AnonymousType#1>' 到 'System.Collections.Generic.List<--db table here-->'。
var qry = context.Projects
.Join(context.Members, p => p.ID, m => m.ID, (p, m) => new { p, m })
.Where(u => u.m.ID == memId)
.Select(b => new {
b.p.ProjName,
b.p.ProjDesc,
b.p.ProjectType,
b.p.Tags
});
return qry.ToList();
【问题讨论】:
-
错误信息很容易解释。您的方法的返回类型与您实际返回的类型不匹配。他们需要匹配。这也不例外,这是一个编译时错误。大不同。