I have this Repository method which uses QueryOver API
public IList<Message> ListMessagesBy(string text, IList<Tag> tags, int pageIndex, out int count, out int pageSize)
{
pageSize = 10;
var likeString = string.Format("%{0}%", text);
var query = session.QueryOver<Message>()
.Where(Restrictions.On<Message>(m => m.Text).IsLike(likeString) ||
Restrictions.On<Message>(m => m.Fullname).IsLike(likeString));
if (tags.Count > 0)
{
var tagIds = tags.Select(t => t.Id).ToList();
query
.JoinQueryOver<Tag>(m => m.Tags)
.WhereRestrictionOn(t => t.Id).IsInG(tagIds)
.TransformUsing(Transformers.DistinctRootEntity);
}
count = 0;
if(pageIndex < 0)
{
count = query.ToRowCountQuery().FutureValue<int>().Value;
pageIndex = 0;
}
return query.OrderBy(m => m.Created).Desc.Skip(pageIndex * pageSize).Take(pageSize).List();
}
I've tried both
.TransformUsing(Transformers.DistinctRootEntity);
and
.RootCriteria.SetResultTransformer(new DistinctEntityRootTransformer())
It screws up both the total count (It returns result none distinct) and the actual paging (Skip / Take)
How can I fix this?
Thanks in advance, Anders