C#C
C#4y ago
Natty

Clean up LINQ statements?

var cashFlowDates = db.CashFlows.Include(cash => cash.Cells).OrderByDescending(cash => cash.Id).FirstOrDefault().Cells.Where(cell => cell.Column == 0).Select(cell => cell.Value).Distinct();
var balanceDates = db.Balances.Include(bal => bal.Cells).OrderByDescending(bal => bal.Id).FirstOrDefault().Cells.Where(cell => cell.Column == 0).Select(cell => cell.Value).Distinct();
var performanceDates = db.Benchmarks.Include(bench => bench.Cells).OrderByDescending(bench => bench.Id).FirstOrDefault().Cells.Where(cell => cell.Column == 0).Select(cell => cell.Value).Distinct();
var allDates = cashFlowDates.Concat(balanceDates).Concat(performanceDates).Distinct();

In an ideal situation I would just do the query on the Cells table, but that table gets updated with ALL the cells, each time a user uploads a file, and there wouldn't be a way to track which data they want to use then (couldn't remove the old data if it was wrong, etc).

What I have here works great, but is there a way to clean up these queries? I.E. Anyway to shorten this? Do I need all the calls here? Does calling Distinct() on each query even make sense (is that slower/faster)? etc.
Was this page helpful?