qq_33359572
qq_33359572
采纳率66.7%
2018-05-29 03:21

mysql 的sql语句与Linq

5
已采纳

SELECT dept.DepartmentId,dept.DptName FROM tbldepartment as dept
JOIN tblconsult as consult on dept.DepartmentId in (consult.DepartmentId ,consult.ApplyDepartmentId)
where consult.Id = 726

这个语句用linq 怎么写 ,主要是 dept.DepartmentId in (consult.DepartmentId ,consult.ApplyDepartmentId) 这一句

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 3年前
     linq的join不支持条件判断,所以要用linq就不能用join了
    
    var query = from dept in tbldepartment
    from consult in  tblconsult
    where dept.DepartmentId == consult.DepartmentId || dept.DepartmentId == consult.ApplyDepartmentId
    select new { dept.DepartmentId, dept.DptName };
    
    点赞 评论 复制链接分享
  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 3年前

    也可以分开来两个join,然后union把查询连起来。

    点赞 评论 复制链接分享