Is there a way I could simplify my lambda expression:
models = _context.something
.Where(i => i.Amount > 0)
.Select(o => new somemodel
{
one = (o.property.prices.Where(i => i.IsCurrent == true).FirstOrDefault().Value - o.property.prices.Where(i => i.IsCurrent == true).FirstOrDefault().Price).ToString(),
two = o.property.prices.Where(i => i.IsCurrent == true).FirstOrDefault().Price,
three = o.property.prices.Where(i => i.IsCurrent == true).FirstOrDefault().Price.ToPriceStr("£"),
four = o.property.rents.Where(i => i.IsCurrent == true).FirstOrDefault().Rent * 1200 / o.property.prices.Where(i => i.IsCurrent == true).FirstOrDefault().Price,
five = Convert.ToInt64(o.property.prices.Where(o => o.IsCurrent == true).FirstOrDefault().Value) * o.property.amount,
six = (Convert.ToInt64(o.property.prices.Where(o => o.IsCurrent == true).FirstOrDefault().Value) * o.property.amount).ToPriceStr("£"),
})
.Distinct()
.ToList();
This is just a sample the real one used the same sort of code many times. It is really prone to error as if I change it I have so many places to do it.
the code o.property.prices.Where(i => i.IsCurrent == true).FirstOrDefault()
is all over my expression. Is there a way I can write in once and reuse it.