Próbuję uruchomić następujące w LINQUzyskiwanie błędu null LINQ; nie możesz wtedy użyć?
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).Sum();
Jednakże pojawia się błąd:
The cast to value type 'Double' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
Próbowałem dodać na ?? 0
; takie, że:
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).Sum() ?? 0;
Jak sugerowano w innych postach to jednak daje błąd:
operator '??' cannot be applied to operands double or int
jakieś sugestie?
EDIT: mój model
namespace RacePace.Models
{
public class Race
{
public int RaceId { get; set; }
[DisplayName("Race Setting")]
public string place { get; set; }
[DisplayName("Distance (km)")]
public double distance { get; set; }
[DisplayName("Date")]
public DateTime date { get; set; }
[DisplayName("Commencement Time")]
public DateTime timeStarted { get; set; }
[DisplayName("Active")]
public Boolean active { get; set; }
[DisplayName("Description")]
public string description { get; set; }
[DisplayName("Creator")]
public int UserId { get; set; }
}
}
Czy 'odległość' jest zerowa? – mattytommo
Niestety, ten sam komunikat staje się "Opperatorem" ?? nie można zastosować do "podwójnego" lub "ruchomych" – NickP
Czy możesz pokazać swój model? – Alex