3
 SELECT   Sum(dbo.amzOrdersItem.price) as SubTotal, 
          Sum(dbo.amzOrdersItem.shippingPrice) as ShippingTotal, 
          Sum(dbo.amzOrdersItem.price) + Sum(dbo.amzOrdersItem.shippingPrice) as OrderTotal
 FROM     dbo.amzOrders INNER JOIN
          dbo.amzOrdersItem ON dbo.amzOrders.amzOrderId = dbo.amzOrdersItem.amzOrderId
 WHERE    dbo.amzOrders.id = '14818'
 GROUP BY dbo.amzOrders.id
4

2 回答 2

0

查询将如下所示:

var query =
    from order in db.amzOrders
    join item in db.amzOrdersItems on order.amzOrderId equals item.amzOrderId
    where order.Id == 14818
    group item by order.Id into g
    select new
    {
        SubTotal = g.Sum(i => i.Price),
        ShippingTotal = g.Sum(i => i.ShippingPrice),
        OrderTotal = g.Sum(i => i.Price) + g.Sum(i => i.ShippingPrice),
    };

我不确定 L2SQL 查询提供程序是否能够OrderTotal确定正确地翻译该行,希望它足够简单。

于 2012-08-07T16:40:26.250 回答
0

也许这个(但未经测试):

var result = from order in Context.amzOrders
             where order.id == '14818'

             from orderItems in Context.amzOrdersItem
               on order.amzOrderId equals orderItems.amzOrderId
             into orderItemsJoinData

             let subTotal = orderItemsJoinData.Sum( item => item.price )

             let shippingTotal = orderItemsJoinData.Sum( item => item.shippingPrice )

             select new 
             {
                 SubTotal = subTotal ,
                 ShippingTotal = shippingTotal,
                 OrderTotal = subTotal + shippingTotal
             };
于 2012-08-07T16:41:51.337 回答