Click here to Skip to main content
15,908,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
how covert this code to lint entity
C#
select optionID,PollID,OptionText,Votes from TPollOptions
            where pollID in(select PollID from TPollquestions where Iscurrent=1 and Isarchived=0);

iam use this code but wrong
C#
var query = from p in db.pollOptions
                      where p.PollID.Contains(db.pollquestions.Where(x => x.IsCurrent == true))
                      select p;
Posted

You have to use 2 queries
C#
var idQuery = from q in db.pollquestions where q.IsCurrent select q.PollID;
var mainQuery = from p in db.pollOptions where idQuery.Contains(p.PollID) select p;

P.S. Correct syntax errors as necessary.
 
Share this answer
 
Depeding on the data you may also use join. Something like this
C#
var query = from p in db.pollOptions
            join db in db.pollquestions on db.PollId equals p.PollId
            where db.Iscurrent=1 
            && db.Isarchived=0
            select p;

If that would bring duplicates one option is to select only distinct records from the query.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900