-4

以下 sql 语句工作正常,但它如何转换为 linq (VB) ?

我在网上找了一些工具,但没有用...

谢谢

SELECT distinct a.sid, a.DisplayName, 
    CASE WHEN b.sID IS NOT NULL THEN 1 ELSE 0 END AS Type1,
    CASE WHEN c.sID IS NOT NULL THEN 1 ELSE 0 END AS Type2,
    CASE WHEN d.sID IS NOT NULL THEN 1 ELSE 0 END AS Type3
FROM dbo.vHRIS_EmailAlert a
LEFT JOIN dbo.vHRIS_EmailAlert b ON a.sid = b.sid AND b.Type = 4
LEFT JOIN dbo.vHRIS_EmailAlert c ON a.sid = c.sid AND c.Type = 5
LEFT JOIN dbo.vHRIS_EmailAlert d ON a.sid = d.sid AND d.Type = 6

where a.CID=37
and (b.Type=4 or c.Type=5 or d.Type=6) 

以下是我的 linq。我通过 LINQPad 运行我的 linq,它返回“语法错误”

(From a In db.vHRIS_EmailAlerts _
Group Join b In db.vHRIS_EmailAlerts _
      On New With { a.SID, .Type = 4 } _
  Equals New With { b.SID, .Type = CType(CLng(b.Type),Int64?) } Into b_join = Group _
From b In b_join.DefaultIfEmpty() _
Group Join c In db.vHRIS_EmailAlerts _
      On New With { a.SID, .Type = 5 } _
  Equals New With { c.SID, .Type = CType(CLng(c.Type),Int64?) } Into c_join = Group _
From c In c_join.DefaultIfEmpty() _
Group Join d In db.vHRIS_EmailAlerts _
      On New With { a.SID, .Type = 6 } _
  Equals New With { d.SID, .Type = CType(CLng(d.Type),Int64?) } Into d_join = Group _
From d In d_join.DefaultIfEmpty() _
Where _
  CLng(a.CID) = 37 And _
  (CLng(b.Type) = 4 Or _
  CLng(c.Type) = 5 Or _
  CLng(d.Type) = 6) _
Select  _
  SID = CType(a.SID,Int32?), _
  a.DisplayName, _
  Type1 = If( _
  Not b.SID Is Nothing, 1, 0), _
  Type2 = If( _
  Not c.SID Is Nothing, 1, 0), _
  Type3 = If( _
  Not d.SID Is Nothing, 1, 0)) _
).Distinct.ToList
4

1 回答 1

-1

转换为 linq 真的很复杂。所以我创建了一个 VIEW 而不是使用 linq

于 2013-08-09T00:57:31.230 回答