c# - How to solve the cast to value type 'System.Decimal' failure error -
the cast value type 'system.decimal' failed because materialized value null. either result type's generic parameter or query must use 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);
edit: sounds 1 of mapped types resolving null. such quantity or price fields.
check schema/mapping make sure if nullable mapped nullable type.
Comments
Post a Comment