Linq查询相当于sql

时间:2012-04-05 19:01:53

标签: c# linq linq-to-sql linq-to-entities

我在Linq中有这个代码。任何人都可以提供t-sql。谢谢!

var tsr = from t in db.Tngs
from l in t.TngUsr
from td in t.TngDepts
from u in db.Users
where t.TId == tId && u.UserId == l.UserId && u.Departments.DeptId == td.Departments.DeptId

是左外的第二个/第三个?

2 个答案:

答案 0 :(得分:7)

尝试在LinqPad中运行它。它将显示您的linq代码的T-SQL等价物。它甚至会将linq表达式转换为等效的Lambda表达式。

答案 1 :(得分:1)

看起来像这样:

SELECT t, l, td, u
FROM Tngs
JOIN TngUser ON TngUser.UserID = Users.UserID
JOIN Users ON Users.UserID = TngUser.UserID
JOIN Departments ON DepartmentID = tngDepartmentID
WHERE Tngs.TId = tId