The cast to value type 'System.Decimal' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
public class Bar
{
[Key]
public int BarID { get; set; }
public int Quantity { get; set; }
public decimal? UnitTotal{get { return Quantity * (Pricelist == null ? 0 : Pricelist.Price); }}
public decimal? DailyTotal { get; set; }
public int PricelistID { get; set; }
public virtual Pricelist Pricelist { get; set; }
}
bar.DailyTotal = db.Bars.Sum(h => h.Quantity * h.Pricelist.Price);