Select with Distinct in API


How would I add a 'Distinct' to the following code, as in 'Select Distinct LastName from Person'.

Dim aQuery As Query = Query.From(Table.Person).Select("Lastname")
Dim iPersons = Session.Source.GetCollection(aQuery)



  • I think you just add distinct at the end of your query definition:

    Dim aQuery As Query = Query.From(Table.Person).Select("Lastname") Distinct
  • In reply to Tim.Young:

    Hi Tim,

    I don't see that method as being available on the Select().

    There is a .Distinct() on the IEntityCollection, but that doesn't return Distinct on Firstname.
    There are various possibilities to add Query Parameters...but not sure if that's the way.

  • In reply to Robert.Byrne:

    This should do the trick.

    Dim aQuery As Query = Query.From(Table.Person).Select(Table.Person.LastName)
    Dim iPersons = Session.Source.GetCollection(Of Person)(aQuery).Distinct(Function(t) t.LastName)

    I saw you used some of the typed entity wrapper goodies so I did this myself as well.