编辑我的Repository类时会弹出一个错误
var applicantList = (from a in context.Profiles
join app in context.APPLICANTs
on a.PROFILE_ID equals app.Profile_id into joined
from j in joined.DefaultIfEmpty()//.OrderBy(v => v.APPLICANT_ID)
select j //<-- this is APPLICANTs type
).Take(1000);
applicantdata = applicantList
.SelectMany(c => c.APPLICANTs) //this line added
.AsQueryable().OrderBy(v => v.APPLICANT_ID).ToList();
if (applicantdata.Any())
{
Cache.Set("applicants", applicantdata, 30);
}
}
return applicantdata;
我在
有例外.SelectMany(c => c.APPLICANTs) //this line added
说:
无法从用法推断出方法'System.Linq.Queryable.SelectMany(System.Linq.IQueryable,System.Linq.Expressions.Expression&gt;&gt;)'的类型参数。尝试明确指定类型参数
答案 0 :(得分:4)
SelectMany接受一个对象集合,每个对象都有一个集合属性。
您在第一个语句中选择了APPLICANTs集合,并在其上运行SelectMany似乎没有意义。
查看这些链接以更好地了解SelectMany。
http://msdn.microsoft.com/en-us/library/bb534336.aspx
Difference Between Select and SelectMany
答案 1 :(得分:1)
SelectMany用于“展平”列表列表。您没有此处的列表列表。您有一个匿名连接行列表。
推断您要查询的内容有点困难,但如果您想获取相关的行(APPLICANTs行),可以使用:
var applicantList = (from a in context.Profiles
join app in context.APPLICANTs
on a.PROFILE_ID equals app.Profile_id
select app).Take(1000)