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)
contains会查2次.
改成表连接查询吧.
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;
解决了 用连接查询 谢谢
用contains不行?
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)
{
}
}
}