【发布时间】:2010-12-09 12:06:21
【问题描述】:
非常感谢您详细解释(以及是否)在这些情况下,以下 Linq to Entities 相关代码 sn-p 的幕后情况有所不同:
A. "foreach" 循环在 "using" 子句中
B. 我使用的是在 Linq to Sql 上运行查询的类似映射,而不是 Linq to Entites。
C. A+B。
代码:
ILookup<string, tblProduct> productBooks;
using (TbsDBEntities tbsDbEntities = new TbsDBEntities())
{
productBooks = (from tbsDbEntity in tbsDbEntities.tblProducts
orderby tbsDbEntity.Title
select tbsDbEntity).ToLookup(p => p.Title.Substring(0, 1).ToUpper());
}
foreach (IGrouping<string, tblProduct> productBook in productBooks)
{
if (productBook.Key[0] >= 'A' && productBook.Key[0] <= 'Z')
{
HtmlAnchor anchor = new HtmlAnchor();
anchor.InnerText = productBook.Key+" ";
anchor.HRef ="/"+ productBook.Key;
divHeader.Controls.Add(anchor);
}
【问题讨论】:
标签: c# .net linq linq-to-sql linq-to-entities