I have files in one table and file actions in another. I want to get the most recent file that Jeff has taken action on that has a status of 4. In SQL, that looks like this:
SELECT TOP 1 files.* FROM files LEFT OUTER JOIN fileActions ON files.FileId = fileActions.FileId WHERE fileActions.ActionTaker = 'Jeff' AND files.FileStatus = 4 ORDER BY fileActions.ActionDate DESC
How would I express this same query in Linq?
I've tried a number of things, but I can't even get it to compile. I feel like this is the closest I have come thus far, but obviously "top" isn't a linq syntax word, so I have a good way to go:
var file = from f in context.Files join fa in context.FileActions on f.FileId equals fa.FileId where fa.ActionTaker == "Jeff" where f.FileStatus == 4 orderby fa.ActionDate descending select top 1 f;
Any help is appreciated.