I have the following code to retrieve customer name, total (orders ), sum (order details) for reach customer in Northwind database. The problem with below code is that it raises an exception since a few customers dont have any entry in orders table.
I know using the query syntax (join) the exception can be avoided. I want to know if the same can be handled with the extension method syntax.
var customerOrders = db.Customers
.Select(c => new
{
CompanyName = c.CompanyName,
TotalOrders = c.Orders.Count(),
TotalQuantity = c.Orders
.SelectMany(o => o.Order_Details).Sum(o=>o.Quantity)
});