通过子查询将SQL转换为LINQ查询

时间:2013-05-24 08:58:45

标签: c# linq linq-to-entities

请问有人可以帮助我将以下SQL的例子放到C#中的LINQ查询中,我使用的是.NET 4.0。

       SELECT x.*
          FROM [eBookAddict].[dbo].[UrlRecord] x
          JOIN (SELECT t.Slug
                  FROM [eBookAddict].[dbo].[UrlRecord] t
              GROUP BY t.Slug
                HAVING COUNT(t.Slug) = 2) y ON y.Slug = x.Slug

非常感谢,

1 个答案:

答案 0 :(得分:2)

from x in db.UrlRecord

join y in db.UrlRecord.GroupBy(rec => rec.Slug).Where(grp => grp.Count == 2)
on y.Key equals x.Slug

select x;