EF-联合查询-结果集-Group by-统计数目

EF框架用着痛并且快乐着···

毕竟用习惯了SQL语句直接硬查的···

 

SELECT C0.ID,C_C.Name,C_C.C_COUNT FROM article_type C0 
INNER JOIN(SELECT C.Name,COUNT(C.Name) AS C_COUNT FROM article_type C 
INNER JOIN article_Info A ON C.ID = A.SeventSortID GROUP BY C.Name) C_C ON C0.Name = C_C.Name

但是项目中用的EF、改吧、搜来搜去总算给拼出来了、、、

也算是EF进程中的一个进步吧···

 

 

                var count =
                    (from e_ in db.article_type
                     join a_a in
                    (from a in db.article_Info
                     from e in db.article_type
                     where a.SeventSortID == e.ID
                     group e by e.Name into g
                     select new
                     {
                         g.Key,
                         Count_ = g.Count()
                     }) on e_.Name equals a_a.Key
                     select new
                     {
                         ID = e_.ID,
                         Name = e_.Name,
                         count = a_a.Count_
                     }).ToList();

。。。

posted @ 2016-10-12 16:58  zh89233  阅读(5552)  评论(0编辑  收藏  举报