score:1

Accepted answer

Maybe something like this (as a query expression);

var lmonthlyTargetvalue = from m in lmonthlyReport
             let Monthly_TargetValue = absolute ? m.Monthly_TargetValue : m.Monthly_TargetValue / 100
             select new { Monthly_TargetValue , m.Month };

That might even be slight overkill for this, as it introduces an extra anonymous type behind the scenes. This is OK too;

var lmonthlyTargetvalue = lmonthlyReport.Select(m => new
{
    Monthly_TargetValue = absolute ? m.Monthly_TargetValue : m.Monthly_TargetValue  / 100,
    m.Month
});

score:0

 //If the Target value is percentual it is divided by 100
if (!Absolute)
{
     lmonthlyReport.Select(m => new { m.Monthly_TargetValue, m.Month, dividedValue = m.Monthly_TargetValue/100 });
}

score:0

Maybe something like:

var lmonthlyTargetvalue = 
    lmonthlyReport.Select(m => new 
    { 
         IsAbsolute(m.Monthly_TargetValue) ? m.Monthly_TargetValue : m.Monthly_TargetValue / 100, 
         m.Month 
    });

Where IsAbsolute is whatever function you use to check whether the target value is a percentage or not.

This will immediately project the correct value into your variable

score:2

this should work;

IQueryable<lmonthlyReport> lmonthlyTargetvalue = lmonthlyReport
                       .Select(m => new { m.Monthly_TargetValue, m.Month });

IList<lmonthlyReport> _temp = new List<lmonthlyReport>();

foreach(var item in lmonthlyTargetvalue){

  _temp.Add(new lmonthlyReport {

    Monthly_TargetValue = item.Monthly_TargetValue / 100,

    Month = item.Month

  });

}

return _temp.AsQueryable();

Related Articles