This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Select with Distinct in API

Hi,

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)

thanks,

Rob.

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

    Dim aQuery As Query = Query.From(Table.Person).Select("Lastname") Distinct
  • 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.

    Rob.
  • 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.

    HTH