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.
私は?? 0
に追加しようとしましたが、
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;
は、しかし、これはエラーを生成:よう
operator '??' cannot be applied to operands double or int
任意の提案ですか?
EDIT:私のモデル
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; }
}
}
'distance'はヌル可能ですか? – mattytommo
残念ながら、メッセージは 'Opperator'? ' 'double'または 'float'に適用できません – NickP
モデルを表示できますか? – Alex