When using sum with lambda in Linq to SQL using the following code:
int query = (from f in odc.RDetails
where f.ticketID == int.Parse(ticket.ToString())
select f).Sum(x => x.Rate);
I get the following error:
The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
. You have to make sure
x.Rateis anint, and not anint?(anintthat acceptsnullas a value).. If the query has no elements,
.Sumwon’t do anything and will returnnull. Choose a default value, let’s say0.