1
select SF.FOLDER_NAME,SF.CREATED_DATE,COUNT(st.FOLDER_ID) 
from SURVEY_FOLDER SF with (nolock) left outer join SURVEY_TEMPLATE ST with (nolock) 
on SF.FOLDER_ID=ST.FOLDER_ID 
group by SF.FOLDER_NAME,SF.CREATED_DATE

我在 Linq 中需要这个查询:

我试过这个查询,但无法group by

我的 Linq 查询:

var data = (from xx in VDC.SURVEY_FOLDER
                        join yy in VDC.SURVEY_TEMPLATE
                        on xx.FOLDER_ID equals yy.FOLDER_ID into g
                        from grt in g.DefaultIfEmpty()
                        select
                        new
                        {
                            xx.FOLDER_NAME,
                            xx.CREATED_DATE,
                            count = g.Count()
                        }).ToList();
4

1 回答 1

0

我得到了答案:

var data5 = (from SF in VDC.SURVEY_FOLDER
                         join ST in VDC.SURVEY_TEMPLATE on new { FOLDER_ID = SF.FOLDER_ID } equals new { FOLDER_ID = (Int64)ST.FOLDER_ID } into ST_join
                         from ST in ST_join.DefaultIfEmpty()
                         group new { SF, ST } by new
                         {
                             SF.FOLDER_NAME,
                             SF.CREATED_DATE
                         } into g
                         select new
                         {
                             g.Key.FOLDER_NAME,
                             CREATED_DATE = (DateTime?)g.Key.CREATED_DATE,
                             Column1 = (Int64?)g.Count(p => p.ST.FOLDER_ID != null)
                         }).ToList();
于 2013-06-11T08:53:18.777 回答