Get children count with restrictions using QueryOver on NHibernate

本小妞迷上赌 提交于 2019-11-30 14:09:19

After some more research, this is the resulting query that works:

Club clubAlias = null;

                IEnumerable<ClubIndexViewModelLineSummary> results = 
                 _querySession.QueryOver<Club>(() => clubAlias)
                    .OrderBy(c => c.IsActive).Desc
                    .OrderBy(c => c.Name).Asc
                    .SelectList(list => list
                                            .Select(c => c.Id).WithAlias(() => sum.Id)
                                            .Select(c => c.Name).WithAlias(() => sum.Name)
                                            .Select(c => c.IsActive).WithAlias(() => sum.IsActive)
                                            .Select(c => c.NumberOfWeeks).WithAlias(() => sum.NumberOfWeeks)
                                            .SelectSubQuery
                                            (
                                                QueryOver.Of<ClubMembership>()
                                                    .Where(c => c.Canceled == false)
                                                    .And(c=> c.Club.Id == clubAlias.Id)
                                                    .ToRowCountQuery()
                                            ).WithAlias(()=> sum.ActiveMembers))

                    .TransformUsing(Transformers.AliasToBean<ClubIndexViewModelLineSummary>())
                    .Skip(start)
                    .Take(15)
                    .Future<ClubIndexViewModelLineSummary>();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!