How can I make a if
within Linq
for example I have the code:
lstParentLines = dbContext.Packages.Select(p => new SummaryViewModel
{
Id = p.Id,
Package = p.Name,
CurrentTotal = budgMonthDetails.Where(bm => bm.CostCenterId == costCenterId &&).Sum(bm => (decimal?)bm.Total) ?? 0,
PreviousForecast = budgMonthDetails
.Where(bm => bm.CostCenterId == costCenterId )
.Sum(bm => (decimal?)bm.Forecast) ?? 0,
VarTotalVSFrcst = (decimal?)(budgMonthDetails
.Where(bm => bm.CostCenterId == costCenterId)
.Sum(bm => (decimal?)bm.Total) ?? 0) / ((budgMonthDetails.Where(bm => bm.CostCenterId == costCenterId).Sum(bm => bm.Forecast))) ?? 0
}).ToList();
So if bm.Total
is zero the division is: bm.Forecast
between bm.Total
But if bm.Total
is greater than zero, the division is: bm.Total
between bm.forecast