开发者

Linq-to-SQL problem

Find all customers whose purchase is less than 10000

var Customer = from c in _NorthWindDataContext.Customers
               join o in _NorthWindDataContext.Orders on c.CustomerID equals o.CustomerID
               group c by c.CustomerID into CutGroup
               where CutGroup.Sum(tab => tab.Orders.Sum(t => t.Order_Details.Sum(t1 => t1.Quantity * t1.Quantity))) < 10000
               select new
               {
                  CustomerID开发者_高级运维 = CutGroup.Key,
                  Total = CutGroup.Sum(tab => tab.Orders.Sum(t => t.Order_Details.Sum(t1 => t1.Quantity *  t1.Quantity))),
               };

I have solved it but if I want to access Order table information then how can I access...

For your information I am binding customer to grid....so I can not use for each


If I understood correctly what you want, you can try this:

    var Customer = from c in _NorthWindDataContext.Customers
                join o in _NorthWindDataContext.Orders on c.CustomerID equals o.CustomerID
                group c by c.CustomerID into CutGroup
                where CutGroup.Sum(tab => tab.Orders.Sum(t => t.Order_Details.Sum(t1 => t1.Quantity * t1.Quantity))) < 10000
                select new
                {
                    CustomerID = CutGroup.Key,
                    Total = CutGroup.Sum(tab => tab.Orders.Sum(t => t.Order_Details.Sum(t1 => t1.Quantity * t1.Quantity))),

                    Orders = from os in _NorthWindDataContext.Orders where os.CustomerID == CutGroup.Key select os,
                };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜