I have the following LINQ to SQL query:
var inTransitStocks = orderHistories.Where(oh => oh.Shipped_Qty > 0)
.Select(oh => oh.Shipped_Qty);
var inTransitStock = (int)inTransitStocks.Sum();
Without a call, ToListI get an exception below in the line Sum():
A null value cannot be assigned to a member of type System.Double, which is a value type that is not null.
If I add .ToList()before the sum (as shown in the comment), I do not get an error.
Why am I getting the error in the first place? ( Shipped_Qtynon-null and no null data in db)
Why is a ToList()patch being added ?
The sql query is executed below (for a query larger than the above):
SELECT [t0].[Shipped Qty]
FROM [dbo].[Order History] AS [t0]
WHERE ([t0].[Shipped Qty] > @p0) AND ([t0].[CUST_ID] = @p1) AND ([t0].[SHIP_TO_ID] = @p2) AND ([t0].[Item] = @p3) AND (([t0].[DT_LST_SHP] >= @p4) OR (UNICODE([t0].[LN_STA]) = @p5))
Results are not returned.
source
share