richardwhatever
richardwhatever

Reputation: 5153

How to get a SELECT DISTINCT on a SelectMulti query in ServiceStack OrmLite?

I'm trying to get a distinct result set of tuples, but the Distinct never gets added to query.

Example

  List<Tuple<Alpha, Beta>> results;

  var q = dbConn.From<Alpha>()
          .Join<Alpha, Beta>((a, b) => a.Id == b.AlphaId)
          ... 
          ... more joins and Wheres
          ...
          .SelectDistinct();

  results = dbConn.SelectMulti<Alpha, Beta>(q);

Adding the SelectDistinct, or not, make no difference to the outputted SQL and hence results.

How do I get SelectMulti to work with Distinct?

Thanks.

Upvotes: 3

Views: 605

Answers (1)

mythz
mythz

Reputation: 143349

I've just added support for this in this commit where if .SelectDistinct() is used in the SqlExpression<T> then it will execute the SQL query using SELECT DISTINCT, e.g:

var results = dbConn.SelectMulti<Alpha, Beta>(q.SelectDistinct());

This change is available from v5.4.1 that's now available on MyGet.

Upvotes: 3

Related Questions