title: LINQ: Get unique rows by selected ID's based on latest time
body: <p>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.</p>
  
  <p>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[].    </p>
  
  <pre><code>            using (var scope = _scopeFactory.CreateScope())
              {
                  var dbContext = scope.ServiceProvider.GetRequiredService&lt;AisRecordContext&gt;();
                  var query = dbContext.SimpleAisRecords
                      //LINQ statements goes here to get intended result
                      .Where ?
                      .GroupBy ?
                      .Select? 
                      .OrderderByDecending ?
  
              }
  </code></pre>
  
  <p>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. </p>
  
  <p>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.<br>
  Would I use ToList? ToArray? or somehow just have my query be the result without modifying it after it gets added. </p>
  
  <p>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) </p>