2012-07-24 164 views
0

我想一個LINQ to SQL的查詢相當於寫下面的SQL查詢:的LINQ to SQL查詢與GROUP BY

select * from [TableA] 
INNER JOIN (select C1, COUNT(*) C2 FROM [Table2] GROUP BY C1) av ON [TableA].C1 = av.C1 
WHERE av.C2 > 10 

任何一個可以幫我如何編寫相當於鏈接查詢。

回答

2
var query = from b in context.TableB 
      group new { c1 } by new 
      { 
       b.c1 
      } into GroupByC1 
      select new 
      { 
       c1 = GroupByC1.Key.C1, 
       count1 = GroupByC1.count() 
      } 

var result = from a in tableA 
      join b in query on a.c1 equals b.c1 
      where b.count1 > 10 
+0

謝謝普拉文 – 2012-07-24 09:02:37