首页 新闻 会员 周边 捐助

linq中子查询用法

0
悬赏园豆:10 [已解决问题] 解决于 2016-08-08 14:02

select * from SearchFile where ID in (select fileid from View_1 where RoleID =1)

这句sql转换成linq怎么写?

view是个视图,包含 id,expr1(中的id),roleid,fileid (searchfile中的id)

select * from SearchFile where ID in (select fileid from View_1 where RoleID =1)
唐宋元明清丶的主页 唐宋元明清丶 | 初学一级 | 园豆:95
提问于:2016-08-08 13:35
< >
分享
最佳答案
0

contains会查2次.

改成表连接查询吧.

收获园豆:10
吴瑞祥 | 高人七级 |园豆:29449 | 2016-08-08 13:42
int temp = int.Parse(ddlSearchFileRole.SelectedValue);// role.id
var result = from a in dc.SearchFile
                             join b in dc.View_1 on a.ID equals b.FileID
                             where b.RoleID == temp
                             select a;
                query = result;

解决了 用连接查询 谢谢

唐宋元明清丶 | 园豆:95 (初学一级) | 2016-08-08 14:00
其他回答(2)
0

用contains不行?

顾晓北 | 园豆:10898 (专家六级) | 2016-08-08 13:38
0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AppYTG.ADBML.GKMYDCP;

namespace AppYTG.WEB.GKMYDCP
{
public partial class GKMYDCP_LIST : System.Web.UI.Page
{
protected int pageNumber; protected Pager pager;
private const int pageSize = 10;

GKMYDCPDataContext db = new GKMYDCPDataContext();
string mpower = "";
string mdepart = "";
string muser = "";
protected void Page_Load(object sender, EventArgs e)
{
mpower = Session["YHQX"].ToString();
mdepart = Session["deptNum"].ToString();
muser = Session["TrueName"].ToString();
if (!string.IsNullOrEmpty(this.txtID.Value))
{
try
{

db.GKMYDCP.DeleteOnSubmit(db.GKMYDCP.Single(p => p.ID == Int32.Parse(txtID.Value)));
db.SubmitChanges();
this.txtID.Value = string.Empty;
}
catch (Exception t)
{
;
}
}
databinds();
}
private string zrReturn(string bt)
{
if (string.IsNullOrEmpty(bt))
{
return "未审批";
}
else
{
return bt;

}

}
int i = 1;
private int bhReturn(int bt)
{

return i++;

}
private void databinds()
{
var qs = from p in db.GKMYDCP
orderby p.ID descending
select new
{
ID = p.ID,
SQDW = p.SQDW,
SQR = p.SQR,
SQSJ = p.SQSJ,

QCR = p.QCR,
QCBM = p.QCBM,
BMZRYJ = zrReturn(""),
ID1 = bhReturn(p.ID)
};
if (mpower == "1")//个人
{
qs = qs.Where(q => q.QCR.Contains(muser));


}
else if (mpower == "2")//部门
{
qs = qs.Where(q => q.QCBM.Contains(mdepart));


}
else if (mpower == "3")//全部
{
;


}

if (!string.IsNullOrEmpty(this.SQDW.Text))
qs = qs.Where(q => q.SQDW.Contains(this.SQDW.Text));
if (!string.IsNullOrEmpty(this.mSQSJ.Value))//日期
qs = qs.Where(q => q.SQSJ.Contains(this.mSQSJ.Value));
if (!string.IsNullOrEmpty(this.SQR.Text))
qs = qs.Where(q => q.SQR == this.SQR.Text);

 

 


pageNumber = ConvertEx.StrToIntDef(Request["page"], 1);
//初始化分页类
pager = new Pager(10, qs.Count(), pageNumber, "GKMYDCP_LIST.aspx");
Repeater1.DataSource = qs.Skip((pageNumber - 1) * pageSize).Take(pageSize);
Repeater1.DataBind();

 

 

 

 

}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
try
{

databinds();
}
catch (Exception ss)
{
;
}
}


protected void cxbut_Click(object sender, EventArgs e)
{

}

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{

}
}
}

aCHENa | 园豆:5 (初学一级) | 2016-08-08 13:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册