【发布时间】:2014-06-18 07:43:20
【问题描述】:
当像这样查询和创建两级 RelationShip 时,我的 Foreach 读取问题:
拉姆达:
public IList GetMasterDetailsFilterLang(string language)
{
var query = (_ourServiceCategories
.Where(c => (c.Language == "fa-IR"))
.Select(
c =>
new
{
CatId = c.Id,
CatName = c.Title,
OurServices = c.OurServices
.Select(
o =>
new
{
ServId = o.Id,
ServName = o.Title
}
)
}
)).ToList();
return query;
}
灵巧:
from c in OurServiceCategories
where c.Language == "fa-IR"
select new
{
CatId = c.Id,
CatName = c.Title,
OurServices = from o in c.CategoryOurServices
select new
{
ServId = o.Id,
ServName = o.Title
}
}
结果:
http://i.stack.imgur.com/dll0l.jpg
现在:我不知道这个怎么用,Foreach怎么读?
我想这样阅读:
var ds = OurServiceService.GetMasterDetailsFilterLang(_LangSar);
foreach (var d in ds)
{
//Read Master example : d.Id,d.Title
//do something
foreach (var details in d)
{
//Read Details example : details.Id,details.Name
//do something
}
}
foreach(d.OurService 中的 var 详细信息)
这是我的问题:
http://i.stack.imgur.com/CQOtJ.jpg
我想在这样的 html 代码中显示结果(使用 StringBuilder):
<ul class="container">
<li class="col-md-2">
<h4>Master.Title(1)</h4>
<ul>
<li><a href="index.html">Details.Title(1)</a></li>
<li><a href="index-footer-v2.html">Details.Title(2)</a></li>
<li><a href="index-footer-v3.html">Details.Title(3)</a></li>
</ul>
</li>
<li class="col-md-2">
<h4>Master.Title(2)</h4>
<ul>
<li><a href="elements.html">Details.Title(1)</a></li>
<li><a href="typography.html">Details.Title(2)</a></li>
</ul>
</li>
</ul>
</ul>
【问题讨论】:
标签: linq ienumerable