GROUP BY and HAVING clauses in nHibernate QueryOver

Deadly 提交于 2019-12-04 03:39:35

I guess you may try using a DTO for storing the result, instead of trying to fit the result in a MessageThreadAccess, when it is not one (no Profile).

Maybe you can try :

public class MessageThreadCountDTO
{
    public MessageThread Thread { get; set; }
    public int Nb { get; set; }
}

then

var profiles = new int[] { 1,2,3,4 };

MessageThreadCountDTO mtcDto = null;

var myResult = 
  _laSession.QueryOver<MessageThreadAccess>()
     .WhereRestrictionOn(x => x.Profile.Id).IsIn(profiles)
     .SelectList(list =>
         list.SelectGroup(x => x.MessageThread).WithAlias(() => mtcDto.Thread).
         SelectCount(x => x.MessageThread).WithAlias(() => mtcDto.Nb)
         )
     .Where(Restrictions.Eq(Projections.Count<MessageThreadAccess>(x => x.MessageThread), profiles.Count()))
     .TransformUsing(Transformers.AliasToBean<MessageThreadCountDTO>())
     .List<MessageThreadCountDTO>().FirstOrDefault();

would profiles be a Profile[], and not an int[], then the following line :

.WhereRestrictionOn(x => x.Profile.Id).IsIn(profiles)

should be :

.WhereRestrictionOn(x => x.Profile).IsIn(profiles)

Hope this will help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!