转换为值类型' System.Decimal'失败,因为具体化值为null

时间:2015-06-02 09:28:12

标签: c# linq entity-framework asp.net-mvc-5

 public class Bar
    {
        [Key]
        public int BarID { get; set; }
        public int Quantity { get; set; }
        public decimal UnitTotal { get; set; }
        public decimal? DailyTotal { get; set; }
        public int PricelistID { get; set; }
        public virtual Pricelist Pricelist { get; set; }
    }

//in the BarController Create method

bar.DailyTotal = db.Bars.Sum(x => x.UnitTotal);

1 个答案:

答案 0 :(得分:0)

建议您在数据库的df %>% gather(variable, value, -(month:student)) %>% unite(temp, student, variable) %>% spread(temp, value) # month Amy_A Amy_B Bob_A Bob_B # 1 1 9 6 8 5 # 2 2 7 7 6 6 # 3 3 6 8 9 7 列中显示空值。您可以消除null或将类型更改为UnitTotal