我可能是愚蠢但似乎从来没有在' lambda窗口中显示任何内容。运行代码后。任何人都可以解释它应该如何工作吗?
答案 0 :(得分:13)
如果使用查询语法编写查询,则lambda窗口会将查询转换为方法语法。
尝试运行示例“LINQ to SQL怎么样?”在样本选项卡中的LINQPad 5分钟感应*文件夹中。 (感应= LINQPad错字,不是我的!)
您的代码窗口如下所示:
from p in Products
let spanishOrders = p.OrderDetails.Where (o => o.Order.ShipCountry == "Spain")
where spanishOrders.Any()
orderby p.ProductName
select new
{
p.ProductName,
p.Category.CategoryName,
Orders = spanishOrders.Count(),
TotalValue = spanishOrders.Sum (o => o.UnitPrice * o.Quantity)
}
并且lambda窗口将如下所示:
Products
.Select (
p =>
new
{
p = p,
spanishOrders = p.OrderDetails.Where (o => (o.Order.ShipCountry == "Spain"))
}
)
.Where (temp0 => temp0.spanishOrders.Any ())
.OrderBy (temp0 => temp0.p.ProductName)
.Select (
temp0 =>
new
{
ProductName = temp0.p.ProductName,
CategoryName = temp0.p.Category.CategoryName,
Orders = temp0.spanishOrders.Count (),
TotalValue = temp0.spanishOrders.Sum (o => (o.UnitPrice * (Decimal?)(o.Quantity)))
}
)