i want to convert this SQL to LINQ but i cant compile it. This is my sql to convert
SELECT u.UserID ,
A.Username ,
A.Password ,
A.CreatedOn
FROM dbo.tbl_User U
INNER JOIN dbo.tbl_UserAuthDetail A ON A.UserID = U.UserID
AND A.CreatedOn IN (
SELECT TOP 1
CreatedOn
FROM dbo.tbl_UserAuthDetail U2
WHERE U2.UserID = U.UserID
ORDER BY CreatedOn DESC )
and this is my attempt so far
var q = from u in context.Users
join au in context.UserAuthDetails on u.UserID equals au.UserID &&
(from au2 in context.UserAuthDetails where au2.UserID == u.UserID orderby au2.CreatedOn descending select au2.CreatedOn).ToList().Contains(au.CreatedOn)
Any help would be appreciated.
TIA