本文介绍了如何将此查询转换为linq实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何将此代码转换为lint实体

hi
how covert this code to lint entity

select optionID,PollID,OptionText,Votes from TPollOptions
            where pollID in(select PollID from TPollquestions where Iscurrent=1 and Isarchived=0);



iam使用此代码但错误


iam use this code but wrong

var query = from p in db.pollOptions
                      where p.PollID.Contains(db.pollquestions.Where(x => x.IsCurrent == true))
                      select p;

推荐答案

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;



PS 根据需要纠正语法错误。


P.S. Correct syntax errors as necessary.


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.


这篇关于如何将此查询转换为linq实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 18:19