LINQ到SQL .SUM(),而不群...成 [英] Linq to SQL .Sum() without group ... into
本文介绍了LINQ到SQL .SUM(),而不群...成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的事情:
var itemsInCart = from o in db.OrderLineItems
where o.OrderId == currentOrder.OrderId
select new { o.OrderLineItemId, ..., ..., o.WishListItem.Price}
有没有办法做了。
itemsCart.Sum() //not sure what to pass into the function
要获得o.WishListItem.Price的总和或我要得到另一个IQueryable的< T>从组数据库......到
to get the sum of o.WishListItem.Price or do i have to get another iQueryable< T> from the database with group ... into?
推荐答案
怎么样?
itemsInCart.AsEnumerable().Sum(o=>o.Price);
AsEnumerable 产生差别,这种查询将在本地执行(LINQ至对象)。
AsEnumerable makes the difference, this query will execute locally (Linq To Objects).
这篇关于LINQ到SQL .SUM(),而不群...成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文