When I write the code below with the PreditTotal
argument, the resulting error message is:
The specified conversion (from the concrete type '
System.Decimal
' to the nullable type 'System.Double
') is invalid.
However, in the Model1.edmx
file, it is defined as Nullable<double>
. Why does it change to the Decimal type after execution?
code :
private IEnumerable<BalanceWarning.PaymentData> GetBalanceWarningData(string Year, string Month)
{
using (var db = GetDB())
{
var result = db.V_VIPGetPaymentDataByDeptK
.Where(s => s.Year == Year && s.Month == Month)
.Select(t => new BalanceWarning.PaymentData
{
Year = t.Year,
Month = t.Month,
DeptId = t.DeptId,
PreditPayment = t.PreditPayment,
//PreditCost = (decimal)t.PreditCost,
PreditTotal = (double?)t.PreditTotal
})
.ToList();
return result;
}
}
Model1.edmx view Content
public partial class V_VIPGetPaymentDataByDeptK
{
public string Year { get; set; }
public string Month { get; set; }
public string DeptId { get; set; }
public decimal PreditPayment { get; set; }
public decimal RealPayment { get; set; }
public double PreditCost { get; set; }
public double RealCost { get; set; }
public Nullable<double> PreditTotal { get; set; }
public Nullable<double> RealTotal { get; set; }
}
class PaymentData
public class PaymentData
{
public string Year { get; set; }
public string Month { get; set; }
public string DeptId { get; set; }
public decimal PreditPayment { get; set; }
public decimal PreditCost { get; set; }
public double? PreditTotal { get; set; }
}
View V_VIPGetPaymentDataByDeptK
schema:
Column Name | Data type |
---|---|
Year | varchar |
Month | varchar |
DeptId | varchar |
PreditPayment | decimal |
RealPayment | decimal |
PreditCost | float |
RealCost | float |
PreditTotal | float |
RealTotal | float |