关于Linq离开加入

时间:2017-04-30 14:44:25

标签: linq

select A.Name,B.UserId
from [dbo].[SentryBoxs] as A
left join [dbo].[SentryBoxUsers] as B on A.ID = B.SentryBoxId
and B.UserId = '970500c2-51bd-443e-ae10-585455f2b326'

[enter image description here][

enter image description here

如何通过linq实现???

1 个答案:

答案 0 :(得分:0)

var ans = from A in dboSentryBoxs
          join B in dboSentryBoxUsers on new { A.ID, UserID = "970500c2-51bd-443e-ae10-585455f2b326" } equals new { ID = B.SentryBoxId, B.UserID } into Bjoin
          from B in Bjoin.DefaultIfEmpty()
          select new { A.Name, B.UserID };