❔ Getting the last data registration time for multiple locations
I have the following Sql table, which I access using ef core.
Id | Location | DataValue | RegistrationDate
Id | Location | DataValue | RegistrationDate
I need to find the last registration date for each different location. Currenetly I do the following:
var locations = _dbContext.Table.Select(x=>x.Location).Distinct().ToList();foreach(var location in locations){ var date = _dbContext.Table.Where(x=>x.location = location).OrderBy(x=>x.RegistrationDate).Top(1);}
var locations = _dbContext.Table.Select(x=>x.Location).Distinct().ToList();foreach(var location in locations){ var date = _dbContext.Table.Where(x=>x.location = location).OrderBy(x=>x.RegistrationDate).Top(1);}
This is obviously not great. What would be the propper way to do this?