Hi there,
I have a table that contains the columns
- ID: PK
- FK_ID: Non-unique ID from a related table
- Modified: Datetime
I have the following SQL query that returns the most recent entry for a all FK_IDs.
With TableWithRank as
(
Select *, Rnk = ROW_NUMBER() over (partition by FK_ID order by Modified desc)
from Table
)
Select ID from TableWithRank where Rnk=1
I tried the following Linq
var l = from c in metaData.Table
group c by c.FK_ID into grp
select grp.OrderByDescending(x => x.Modified).First();
I am getting the exception
Couldn't create any correlation filter lambda because the nested query didn't have any correlation filters. Please specify a filter in the nested query to tie the nested query to the parent query
What am I doing wrong?
thank you for your help on this!
Best regards