查询foreach循环 [英] Query in foreach loop
问题描述
我尝试在forreach中调用查询但它显示错误
我尝试过:
i try to call query in forreach but it shows error
What I have tried:
public static string Jqufunc(int yearP)
{
string res = "[";
ProjectdbEntities a = new ProjectdbEntities();
var b = a.Catg_type;
foreach (var c in b)
{
res += "'" + c.Catg_type1 + "',";
}
res = res.Substring(0, res.Length - 1);
res += "]";
var allprogs = a.Program_type;
string res2 = "[";
foreach (var pr in allprogs)
{
res2 += "{name: '" + pr.Prog_name + "',";
var allcats = a.Catg_type;
res2 += "data:[";
var query = (a.Std_info.Join(a.Catg_type, stdtable => stdtable.Catg_id,
catg => catg.Catg_id, (stdtable, catg) => new {stdtable, catg})
.Join(a.Program_type, t => t.stdtable.Prog_id, prog => prog.Prog_id, (t, prog) => new {t, prog})
.Join(a.Year_info, t => t.t.stdtable.year_id, yea => yea.year_id, (t, yea) => new {t, yea})
.Where(t=>t.t.t.stdtable.year_id==yearP)
.GroupBy(
t =>
new { t.t.t.catg.Catg_type1, t.t.prog.Prog_name, t.yea.year, t.t.t.stdtable.Catg_id },
t => t.t.t.stdtable)
.Select(g => new
{
g.Key.Catg_type1,
g.Key.Prog_name,
g.Key.year,
g.Key.Catg_id,
total_students = g.Select(p=>p.Catg_id).Distinct().Count()
})).ToList();
res2 = res2.Substring(0, res2.Length - 1);
foreach(var ab in res2)
{
res2 += query(yearP);
}
}
res2 += "]";
res2 += "},";
return res + "*" + res2;
}
错误
'查询'是'变量'但是像'方法'一样使用
error
'query' is a 'variable' but is used like a 'method'
推荐答案
嗯......是的。它是。
查看消息:
Well...yes. It is.
Look at the message:
'query' is a 'variable' but is used like a 'method'
然后看看你如何创建和使用查询
:
Then look at how you create and use query
:
var query = (a.Std_info.Join(a.Catg_type, stdtable => stdtable.Catg_id,
...
})).ToList();
...
res2 += query(yearP);
query
是List< T>匿名类型。
您不能使用列表作为方法!
我不确定你到底是什么试图在这里做,但是...它不是一种方法, yearP
没有显示,所以它可能是列表的索引,在这种情况下你想要:
query
is a List<T> of an anonymous type.
You can't use a list as a method!
I'm not sure what the heck you are trying to do here, but...it's not a method, yearP
isn't shown, so it could be an index into the list in which case you'd want:
res2 += query[yearP];
但这不起作用,因为匿名类型没有加法运算符......
But that wouldn't work either because the anonymous type doesn't have a addition operator...
这篇关于查询foreach循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!