Linq to sql 将此SQL语句转换为LINQ to SQL

Linq to sql 将此SQL语句转换为LINQ to SQL,linq-to-sql,Linq To Sql,我一直在努力将这个SQL语句转换为LINQ到SQL VB.Net 9.0。我用过Linqer,但没有成功。任何帮助都将不胜感激 select t.TeeId, t.DescriptionId, t.[Description], t.Rating, t.Slope, case when d.TotalHoles <> h.TotalHoles then 0 else 1 end [Status] from dbo.CourseDescription

我一直在努力将这个SQL语句转换为LINQ到SQL VB.Net 9.0。我用过Linqer,但没有成功。任何帮助都将不胜感激

select t.TeeId,
   t.DescriptionId,
   t.[Description],
   t.Rating,
   t.Slope,
   case when d.TotalHoles <> h.TotalHoles then 0
   else 1 end [Status]
from dbo.CourseDescription d
inner join dbo.CourseTees t
on t.DescriptionId = d.DescriptionId
inner join (select TeeId, count(*) as TotalHoles
           from dbo.CourseHoles
          group by TeeId) h
on h.TeeId = t.TeeId
where d.CourseId = 1

这是一个尝试。我没有用VB做任何编程,但我已经尽力使语法尽可能正确。为简单起见,我将其分为两个查询,但使用LINQ to SQL,第一个查询实际上不会产生DB查询。它只是与第二个简单地结合在一起。在枚举第二个查询之前,这两个查询都不会执行。如果需要,添加行连续体。我不知道C中的三元运算符是否有到SQL的转换。如果没有,在select之前对零件进行材质处理,获得d.TotalHoles和h.TotalHoles,然后使用LINQ to对象枚举这些对象并构造状态

dim holes = from h in db.TotalHoles
            groupby h.TeeId into g
            select TeeId = Key, TotalHoles = g.Count()

dim courses = from d in db.CourseDescription
              where d.CourseId = 1
              join t in CourseTees on d.DescriptionId equals t.DescriptionId
              join h in holes on h.TeeId equals t.TeeId
              select t.TeeId,
                     t.DescriptionId,
                     t.Description,
                     t.Rating, t.Slope,
                     Status  = If(d.TotalHoles = h.TotalHoles, 1, 0)

dim holes=从db.TotalHoles组中的h按h.TeeId到g选择TeeId=Key,TotalHoles=g。计数范围变量TeeId隐藏封闭块中的变量或先前在查询中定义的范围变量expression@goforebroke-你可以把它当作钥匙,然后在第二个查询中使用h.Key而不是h.TeeId。至少我认为这正是它所抱怨的。我只是试图编译第一个查询,但它不会。它一直在抱怨。Dim holes=From h In db.DnnGolf_CourseHoles uuu按h.TeeId分组到g=Group uu选择键,TotalHoles=g.count在代码块中有一个更高的statment变量范围…抱歉