Re: Linq Sum() Question
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Thu, 13 Sep 2007 22:03:41 +0200
<Olivier.Paesbrugghe@xxxxxxxxx> wrote in message news:1189683757.167406.72170@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm having a problem with a Linq statement.
I made a console application that makes use of Northwind database.
Made a dbml file of the database whith the designer and now I want to
see the total of all orders of the customers.
I used this statement:
var custTotalOrders = db.Customers
.Select( p =>
new { c.ContactName,
TotalOrders = c.Orders.Sum( o => o.Order_Details.Sum( od =>
od.Quantity * od.UnitPrice))});
(Un)fortunately there is 1 client who hasn't made any orders yet and
so I get an error:
Unhandled Exception: System.InvalidOperationException: The null value
cannot be
assigned to a member with type System.Decimal which is a non-nullable
value type.
Is there something wrong with my expression or is this an error due to
the fact LINQ is still in beta?
kind regards,
Olivier
Supposing UnitPrice is a 'decimal' type...
TotalOrders = c.Orders.Sum( o => (decimal?) o.Order_Details.Sum( od =>...
or only select the customer who have orders:
db.Customers
.Where(q => q.Orders.Count > 0)
.Select(...
Willy.
.
- References:
- Linq Sum() Question
- From: Olivier . Paesbrugghe
- Linq Sum() Question
- Prev by Date: SelectNodes twice
- Next by Date: Re: Event or other?
- Previous by thread: Re: Linq Sum() Question
- Next by thread: Re: Linq Sum() Question
- Index(es):
Relevant Pages
|