I am trying to select a distinct list of values from a table whilst
ordering on another column.

The only thing working for me so far and uses magic strings and an
object array. Any better (type-safe) way?

      var projectionList = Projections.ProjectionList();
      projectionList.Add(Projections.Property("FolderName"));
      projectionList.Add(Projections.Property("FolderOrder"));

      var list = Session.QueryOver<T>()
        .Where(d => d.Company.Id ==
SharePointContextHelper.Current.CurrentCompanyId)
        .OrderBy(t => t.FolderOrder).Asc
        .Select(Projections.Distinct(projectionList))
        .List<object[]>()
        .ToList();

      return list.Select(l => new Folder((string)l[0])).ToList();

btw, doing it with linq won't work, you must select FolderOrder
otherwise you'll get a sql error (`ORDER BY items must appear in the
select list if SELECT DISTINCT is specified.`
)

and then doing that gives a known error : `Expression type
'NhDistinctExpression' is not supported by this SelectClauseVisitor.`
regarding using anonymous types with distinct

     var q = Session.Query<T>()
        .Where(d => d.Company.Id ==
SharePointContextHelper.Current.CurrentCompanyId)
        .OrderBy(d => d.FolderOrder)
        .Select(d => new {d.FolderName, d.FolderOrder})
        .Distinct();
      return q.ToList().Select(f => new Folder(f));

All seems a lot of hoops and complexity to do some sql basics....

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to