我花了几天(也许几周)试图解决这个问题。我有两个表,我试图将我的数据组织到以下层次结构中。这是一个应该是什么样子的示例:
<ul><strong>PageTitle</strong>
<li>Category A</li>
<li>Category B</li>
<li>Category C</li>
我的查询在 LinQPad 中成功运行,但无法在 MVC 中运行。这是我在 MVC 中使用的代码。
public IEnumerable<wl> List()
{
IEnumerable<wl> wlTest;
using (LibEntities _libEntity = new LibEntities()) {
wlTest = (from p in table1
join c in table2 on p.PK equals c.FK
group p by new { c.title } into g
select new wl
{
TitleName = g.Key.title,
Category = from p in g
group p by g.cat_id into d
select new wl{d.Key.cat_id}
}).ToList();
return wlTest;
}
}
这是wl类信息:
public class wl
{
public string TitleName { get; set; }
public string Category { get; set; }
}
我不断得到
无法使用集合初始化程序初始化类型“LibraryProject.Model.wl”,因为它没有实现“System.Collections.IEnumerable”。
好的,这是 LinqPad 中的一个非常相似的查询。
from f_a_p in Find_article_progs
join f_a in Find_articles on f_a_p.Prog_num equals f_a.DbProg
where f_a_p.Parent_id == 183
group f_a by new {f_a_p.Prog_title} into d
select new {
d.Key.Prog_title,
Links = from f_a in d
group f_a by new {f_a.DbTitle} into c
select new {
c.Key.DbTitle
}
}
谁能帮我这个?