jats
jats

Reputation: 137

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

Upvotes: 1

Views: 64

Answers (1)

Slava Kovalchuk
Slava Kovalchuk

Reputation: 523

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,
                };

Upvotes: 1

Related Questions