In my controller I have the following action to get records and return IQueryable records,
var records = GetRecords()
.Select(entry => new
{
List = entry.Select(sl => sl.Names).Distinct().Take(3).ToList()
})
.Select(s => new
{
Entry1 = s.List.FirstOrDefault(),
Entry2 = s.List.Skip(1).FirstOrDefault(),
Entry3 = s.List.Skip(2).FirstOrDefault()
});
I did this to try and lower the database hits from the following,
var records = GetRecords()
.Select(s => new
{
Entry1 = s.Select(sl => sl.Names).Distinct().Take(3).FirstOrDefault(),
Entry2 = s.Select(sl => sl.Names).Distinct().Take(3).Skip(1).FirstOrDefault(),
Entry3 = s.Select(sl => sl.Names).Distinct().Take(3).Skip(2).FirstOrDefault()
});
Is there a better way to get the List to use 3 of the elements in different variables and return an IQueryable.
New contributor
Neoharry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.