导航

linq to sql sum

Posted on 2012-02-15 13:44  유람객  阅读(147)  评论(0编辑  收藏  举报
public int GetCount()
        {
            // Get the count of each item in the cart and sum them up
            int? count = (from cartItems in storeDB.Carts
                          where cartItems.CartId == ShoppingCartId
                          select (int?)cartItems.Count).Sum();
            // Return 0 if all entries are null
            return count ?? 0;
        }