, - , , . .
Linq
double totalDistance =
(from g in db.Logs join h in db.Races
on g.raceId equals h.RaceId where g.userId == id
select h).Sum(x => x.distance) ?? 0;
a >
NULL, , , - , , . EDIT:
double? totalDistanceTemp =
(from g in db.Logs join h in db.Races
on g.raceId equals h.RaceId where g.userId == id
select h).Sum(x => x.distance);
double totalDistance = totalDistanceTemp ?? 0;
THAT , nullables. , , , / LINQ, , - . , .
double? totalDistanceTemp =
(from g in db.Logs join h in db.Races
on g.raceId equals h.RaceId where g.userId == id
select h).Sum(x => (Double?) x.distance);
double totalDistance = totalDistanceTemp ?? 0;
double? totalDistanceTemp =
(from g in db.Logs join h in db.Races
on g.raceId equals h.RaceId where g.userId == id
select ((Double?)h.distance )).Sum();
double totalDistance = totalDistanceTemp ?? 0;
, , : . , LINQ to Objects (nullable ). . / , , , LINQ .
double totalDistance =
(from g in db.Logs join h in db.Races
on g.raceId equals h.RaceId where g.userId == id
select h.distance).AsEnumerable().Sum();
, - , , , - ( , ).