如何将此查询转换为linq实体 [英] how convert this query to linq entity

查看:82
本文介绍了如何将此查询转换为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;

推荐答案

你必须使用2个查询

You have to use 2 queries
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.


取决于数据,您也可以使用join。这样的东西

Depeding on the data you may also use join. Something like this
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实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆