I have managed to connect to my database using the current syntax below and running simple LINQ query's. I have a database containing around 20 unique SHIP_ID's that gets updated information regarding positions for all ships every 2 minutes. That means SHIP_ID and TIMESTAMP combined together are unique, and that my database has a lot of data in it so i want the load to be on the SQL server to return the correct data. And not the client to go through a response of 20k lines to find the value i want.
I want to retrieve the last position stored within the database for a group of select ships, lets says the ships with SHIP_ID's 1, 2 and 3. As of now the SHIP_ID's are stored in a string[].
using (var scope = _scopeFactory.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<AisRecordContext>();
var query = dbContext.SimpleAisRecords
//LINQ statements goes here to get intended result
.Where ?
.GroupBy ?
.Select?
.OrderderByDecending ?
}
How could I go forward making the correct LINQ statements to get the data i want? I also want the result to have the whole row it selects as data, for example LAT, LON, SPEED and HEADING that are some of my other columns.
I also wonder what is the best format to return the result. The result will be the row's that returns, the row where TIMESTAMP is newest for the SHIP_ID's i want to call. I will need all the columns that my database has (about 15 columns) since i will display the data in a map.
Would I use ToList? ToArray? or somehow just have my query be the result without modifying it after it gets added.
Thanks for your time (and sorry for a very specific question, could not find any articles getting multiply rows by selected ID's for their latest DATE)