0

How can I construct the below sql query in linq query to get the results ?

SELECT PageNumber from LMS_SurveyQuestion WHERE SurveyQuestionID IN
(SELECT  SurveyQuestionID from LMS_SurveyQuestionOptionChoice 
WHERE NextPageNumber = 4) and SurveyID = 1

2 Answers 2

1

Have a look at this article. Basically, if you want to implement SQL IN query in LINQ, you need to construct an inner query first, and then use the Contains() method. Here's my attempt:

var innerQuery = (from log in LMS_SurveyQuestionOptionChoice where log.NextPageNumber = 4 select log.SurveyQuestionID);

var result = (from f in LMS_SurveyQuestion where innerQuery.Contains(f.SurveyQuestionID) && f.SurveyID = 1 select f);

Hope this will help.

Sign up to request clarification or add additional context in comments.

1 Comment

But where is SurveyID = 1 is used ? SurveyID belongs to LMS_SurveyQuestion.
1

try this

var result = from l in LMS_SurveyQuestion 
             let lsq = from l_S in LMS_SurveyQuestionOptionChoice 
             where l_S.NextPageNumber = 4
             select l_S.SurveyQuestionID 
             where lsq.Contains(l.SurveyQuestionID) and l.surveyid = 1
             select l.PageNumber;  

1 Comment

But where is SurveyID = 1 is used ? SurveyID belongs to LMS_SurveyQuestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.