Skip to content

How to sequence the column sort order while fetching data from Dataverse using client sdk? #385

@spmanjunath

Description

@spmanjunath

I have parent table called Location and a child table LocationSortOrder, i have used linked entities with left outer join and trying to sort the entities first by LocationSortOrder.SortOrderValue column and then the Location.LocationCode column. I have below code which does not give the desired result.

(Table: Columns)
Location: LocationCode, Description
LocationSortOrder: LocationCode, SortOrderValue


var parentQueryExpression = new QueryExpression(locationEntityName)
        {
            ColumnSet = new ColumnSet(columns),
            NoLock = true
        };

var linkedEntity = new LinkEntity
{
    LinkFromEntityName = locationEntityName,
    LinkToEntityName = locationSortOrderEntityName,
    LinkFromAttributeName = locationIDName,
    LinkToAttributeName = locationCodeName,
    JoinOperator = JoinOperator.LeftOuter,
    EntityAlias = "locationSortOrder",
    Columns = new ColumnSet(columnNames)
};

//(1)//linkedEntity.Orders.Add(new OrderExpression("sortOrderValue", OrderType.Ascending, "Location1SortOrder", locationSortOrderEntityName));

parentQueryExpression.LinkEntities.Add(linkedEntity);

var orderExpressionCollection = new Collection<OrderExpression>
    {
        //(2)//new OrderExpression("sortOrderValue", OrderType.Ascending, "Location1SortOrder", locationSortOrderEntityName),
        new OrderExpression(locationCodeName, OrderType.Ascending, "LocationCode", locationEntityName)
    };

parentQueryExpression.Orders.AddRange(orderExpressionCollection);

Uncommenting //(2)// gives binding error for column 'sortOrderValue'. Uncommenting //(1)// does not sort the column first by 'sortOrderValue' and then by 'locationCode'.

Note: Sorting on locationCode in LocationSortOrder table is not an option because not every record from Location is present in LocationSortOrder table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions