请坛子里的大哥们帮忙把SQL转成LINQ语句。多谢了。

渊浪 2010-10-29 01:27:00
SQL:
SELECT DISTINCT dept.id, dept.forshort, dept.ABC, organization_dept.organizationid
FROM dept
INNER JOIN organization_dept ON dept.id = organization_dept.deptid
WHERE (organization_dept.organizationid
IN (SELECT organization_dept.organizationid
FROM organization_dept
WHERE organization_dept.deptid = @deptid)
AND (dept.ABC LIKE N'%'+ @ABC +'%')
AND (dept.state = 1 OR dept.state = 3)
ORDER BY dept.ABC, dept.forshort

写成LINQ:
前部分:
departmentsDataContext db = new departmentsDataContext();
return db.dept.Where(里面的内容烦请各位达人转一下)
...全文
79 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huminghua 2010-10-29
  • 打赏
  • 举报
回复
上面写错一点点啦!

var organizationidList=from o in organization_dept where o.deptid=@deptid select o.organizationid;

var linqquery=(from d in dept join od in organization_dept on d.id equals od.deptid
orderby d.ABC,d.forshort where organizationidList.Contains(od.organizationid)
&& d.ABC.Contains("+@ABC+") && (d.state==1 || d.state==3)
select new{d.id,d.forshort,d.ABC,od.organizationid}).Distinct()
huminghua 2010-10-29
  • 打赏
  • 举报
回复



var organizationidList=from o in organization_dept where o.deptid=@deptid select o.organizationid;

var linqquery=(from d in dept join od in organization_dept on d.id equals od.deptid
orderby d.ABC,d.forshort where str.Contains(od.organizationid)
&& d.ABC.Contains("+@ABC+") && (d.state==1 || d.state==3)
select new{d.id,d.forshort,d.ABC,od.organizationid}).Distinct()
zhang523012313 2010-10-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 q107770540 的回复:]
C# code


departmentsDataContext db = new departmentsDataContext();
var query =(from dep in db.dept
join o_dep in db.organization_dept
on dep.id equals o_dep.deptid
……
[/Quote]
1楼正解,差不多的。LZ结贴给分哈
q107770540 2010-10-29
  • 打赏
  • 举报
回复


departmentsDataContext db = new departmentsDataContext();
var query =(from dep in db.dept
join o_dep in db.organization_dept
on dep.id equals o_dep.deptid
let ListOrganizationid=db.organization_dept.Where(o=>o.deptid == @deptid).Select(o=>o.organizationid)
where ListOrganizationid.Contains(o_dep.organizationid)
&& dep.ABC.Contains(@ABC)
&& new int[]{1,3}.Contains(dep.state)
orderby dep.ABC,dep. forshort
select new
{
dep.id,
dep.forshort,
dep.ABC,
o_dep.organizationid
}).Distinct();

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧