0

Sir/Ma'am I want to convert the below mentioned SQL query into LINQ how can I achieve this.

select * from dbo.Main as M 
where M.ApplicationId in 
(select distinct R.ApplicationId from tblRecomSanctionedDetail R 
where R.UpdateByUserId = 1011 )

tried using my limited knowledge with LINQ but could not get the output.

Christos
  • 53,228
  • 8
  • 76
  • 108
  • 4
    `DISTINCT` doesn't do anything here, so you can remove it. Check this answer for `IN()` https://stackoverflow.com/questions/51339/how-can-you-handle-an-in-sub-query-with-linq-to-sql – Aaron Dietz Apr 02 '18 at 20:07
  • Thanks Aaron I was able to get the desired result – Laxman Rathod Apr 02 '18 at 20:26

1 Answers1

1

I don’t have anywhere to test this at the moment but I think roughly it would be something like…

var applicationIds = tblRecomSanctionedDetailQueryable.Where(x => x.UpdateByUserId == 1011).Select(x => x.ApplicationId);
var result = mainQueryable.Where(x => applicationIds.Contains(x.ApplicationId)).ToList();
Timovski
  • 571
  • 2
  • 6