Query linq to get the rows with the oldest date in a data set

0

ID (self-generated number) IDFK (self-generated number) but can be repeated DATE (TO DATE) ...

 ID IDFK FECHA
 1 1 1/1/1999
 2 1 1/2/1999
 3 2 1/3/1999
 4 3 1/2/1999
 5 4 1/5/1999
 6 4 1/3/1999
 7 1 1/4/1999

Ok, think that the highest ID does not have to coincide with the later DATE, since there are more parameters that check if the row is valid to be taken.

I think I should do a subquery, but I'm not an expert at the moment for such a difficult query. This is my reason for asking for help. On the one hand I have to group by IDFK, and on the other hand I take the oldest date.

Also if it can be done in two consultations, I accept that solution

in this example the valid data would be

3 2 1/3/1999
4 3 1/2/1999
5 4 1/5/1999
7 1 1/4/1999

Thanks

    
asked by ppm4587 29.05.2017 в 20:32
source

1 answer

0

try this

Dim sortedResult = ClassList.OrderBy(Function(s) s.ID)
                          .ThenBy(Function(s) s.IDFK).ThenBy(Function(s) s.FECHA)

If it does not work, go to link a LINQ tutorial that in my opinion is very good and with examples in both C # and VB.net. Greetings

    
answered by 29.05.2017 в 21:07