How Can I use GroupBy and OrdeBy in my Queries?

 I would like to use GroupBy or OrderBy with the following script, I searched about this but didn't find anything.

Dim jobQr = Query.From(Table.Person).Select("PersonalTitle").Where("IsInActive = 0 and IsExternal = 0 and IdentityType = 'Primary'")
Dim jobR = Session.Source.GetCollection(jobQr, EntityCollectionLoadType.Slim)

Can you help me?

  • For grouping you find a code snippet in the snippet library of the code editor in Designer or Object Browser. Just press F2 (or choose the snippet icon from the toolbar) and select Object layer | Collections | Group collections by column

    For sorting a collection you can use the .OrderBy method in your fluent query definition.

    For example:

    Dim jobQr = Query.From(Table.Person).Select("PersonalTitle").Where("IsInActive = 0 and IsExternal = 0 and IdentityType = 'Primary'").OrderBy("PersonalTitle")
    Dim jobR = Session.Source.GetCollection(jobQr, EntityCollectionLoadType.Slim)

  • Hello Markus,
    I tried this before, but I received the following error message:

    Overload resolution failed because no accessible GetCollection can be called with these arguments

    Expression is of type '?', which is not a collection type.

    Do you have any idea how to resolve this?

  • Sorry, my bad. The Select part of the query object should be the last one.

    Dim jobQr = Query.From(Table.Person).Where("IsInActive = 0 and IsExternal = 0 and IdentityType = 'Primary'").OrderBy("PersonalTitle").Select("PersonalTitle")