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

mysql 的sql语句与Linq

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条回答 默认 最新

  • threenewbee 2018-05-29 04:46
    已采纳
     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 };
    
    已采纳该答案
    打赏 评论
  • threenewbee 2018-05-29 04:46

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

    打赏 评论

相关推荐 更多相似问题