我试图在我的EntitySetController中从我的Get方法返回它之前订购一个集合,这是我的代码:
[Queryable]
public IQueryable<Standing> GetStandings()
{
//order by points, goalsfor-goalsagainst, goalsfor, teamname
IQueryable<Standing> standings = db.Standings.Include("Team").Include("Stage");
var standingsQuery = from s in standings
let points = (s.Won*3) + (s.Drawn*1)
select standings.OrderByDescending(p => points)
.ThenByDescending(g => g.GoalsFor - g.GoalsAgainst)
.ThenBy(t => t.Team.TeamName);
return standingsQuery.AsQueryable();
}
但我收到错误:
Cannot implicitly convert type 'System.Linq.IQueryable<System.Linq.IOrderedQueryable<Standing>>' to 'System.Linq.IQueryable<Standing>'. An explicit conversion exists (are you missing a cast?)
我是否需要单独的方法来返回有序集合?
答案 0 :(得分:1)
试试这样:
[Queryable]
public IQueryable<Standing> GetStandings()
{
//order by points, goalsfor-goalsagainst, goalsfor, teamname
IQueryable<Standing> standings = db.Standings.Include("Team").Include("Stage");
IOrderedQueryable<Standing> standingsQuery = standings
.OrderBy(s => s.Won * 3 + s.Drawn * 1)
.ThenByDescending(s => s.GoalsFor - s.GoalsAgainst)
.ThenBy(s => s.Team.TeamName);
return standingsQuery.AsQueryable();
}
您的代码无效的原因是您返回IQueryable<IOrderedQueryable<Standing>>
而不是IOrderedQueryable<Standing>
。