View Full Version : سوال: کنترل خطای Nullable object must have a value
nezhad313
دوشنبه 19 فروردین 1398, 00:47 صبح
باسلام خدمت اساتید می خواستم در خصوص اینکه بنده متد زیر را نوشتم و یک خروجی دسیمال را برای من بر می گرداند ولی ارور(Nullable object must have a value.) را نشان می دهد میخواستم راهنمایی بفرمائید چطوری بتوانم ضمن کنترل خطا در صورت خالی بودن مقدار صفر را برگرداند .با تشکر
private decimal GetKharid(int year, int month) {
return db.FactorDetaile.Where(a => a.Factor.DateOfBuy.Year == year && a.Factor.DateOfBuy.Month == month && a.Factor.IsBuy == true).Sum(a => a.TotalPrice).Value;
}
Mahmoud.Afrad
دوشنبه 19 فروردین 1398, 01:34 صبح
private decimal GetKharid(int year, int month)
{
var s = db.FactorDetaile.Where(a => a.Factor.DateOfBuy.Year == year && a.Factor.DateOfBuy.Month == month && a.Factor.IsBuy == true).Sum(a => a.TotalPrice);
return (s==null ? 0 : s);
}
samie_shamsi
چهارشنبه 05 آبان 1400, 15:49 عصر
private decimal GetKharid(int year, int month)
{
var s = db.FactorDetaile.Where(a => a.Factor.DateOfBuy.Year == year && a.Factor.DateOfBuy.Month == month && a.Factor.IsBuy == true).Sum(a => a.TotalPrice);
return (s==null ? 0 : s);
}
نفست طلا داداش ، البته از این Syntax هم استفاده بشه عالیه:
public int getSum(int id , string firstDate , string lastDate){
return db.Order_Partner.Where(c=> c.id == id && Convert.ToDateTime(firstDate) <= c.Date && c.Date <= Convert.ToDateTime(lastDate).Select(l=> l.Price).DefaultIfEmpty(0).Sum(); )
}
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.