8,497
社区成员
发帖
与我相关
我的任务
分享
var query = from item in
(from en in dbContext.WK_TK_Module.Where(c => c.State == (int)SYS_State.启用)
join subject in dbContext.WK_TK_Subject.Where(c => c.State == (int)SYS_State.启用) on en.Id equals subject.ModuleId into ts2
from ts in ts2.DefaultIfEmpty()
//join user in dbContext.SYS_User on ts.CreateUserId equals user.Id into tu2
//from tu in tu2.DefaultIfEmpty()
join reply in dbContext.WK_TK_Reply.Where(c => c.State == (int)SYS_State.启用) on ts.Id equals reply.SubjectId into tr2
from tr in tr2.DefaultIfEmpty()
select new
{
ModuleId = string.IsNullOrEmpty(en.Id) ? null : en.Id,
ModuleName = en.Name,
//UserId = tr.Id == "" ? "" : tr.Id,
SubjectId = string.IsNullOrEmpty(ts.Id) ? null : ts.Id,
SubjectCreateUserId = string.IsNullOrEmpty(ts.CreateUserId) ? "asd" : ts.CreateUserId,
ReplyCreateUserId = string.IsNullOrEmpty(tr.CreateUserId) ? null : tr.CreateUserId,
ReplyId = string.IsNullOrEmpty(tr.Id) ? null : tr.Id
}
)
group item by new { item.ModuleName,item.SubjectCreateUserId } into grp
select new
{
ModuleName = grp.Key.ModuleName,
SubjectUserCount =grp.Count(c=>!string.IsNullOrEmpty(c.SubjectCreateUserId)),
//grp.GroupBy(c=>c.SubjectCreateUserId).Count(),
//grp.Select(c => c.SubjectCreateUserId).Distinct().Count(), //主题发表人数
ReplyUserCount = grp.Count(c => !string.IsNullOrEmpty(c.ReplyCreateUserId)),//回复人数
ReplyCount = grp.Count(c => !string.IsNullOrEmpty(c.ReplyId)),//回复数
SubjectCount = grp.Count(c => !string.IsNullOrEmpty(c.SubjectId))//发表数
};
//.ToList<dynamic>();
return query.ToList<dynamic>();