LivePersistence = False and Sorting Issues

Posts   
 
    
pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 07-Jul-2007 11:56:12   

We have used the datasource(LLBLGenProDataSource2) whose LivePersistence is false. And it have been assigned to a datagrid.

We are using the PerformSelect for the Datasource(coding)

Protected Sub dsIssue_PerformSelect(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2)
    .....
    Dim newExpression As New SortExpression
    newExpression.Add(New SortClause(New EntityProperty("IssueType"), Nothing, SortOperator.Ascending))
    adapter.FetchEntityCollection(ecIssue, filter, Nothing, newExpression)
    .....
End Sub

Here it produces the error

Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityProperty' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityProperty' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2'.

We cant directly use

newExpression.Add(IssueFields.IssueType, Nothing, SortOperator.Ascending))

instead of

newExpression.Add(New SortClause(New EntityProperty("IssueType"), Nothing, SortOperator.Ascending))

because the field to be sorted would be found at run time only.So we will be passing the fieldheader as string.

How to solve this casting problem?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 07-Jul-2007 23:58:42   

Can you try setting the Sorter property on the PerformSelectEventArgs instance passed to the PerformSelect event.

This property should have the Add method called to add the SortClause as you have done in your existing code.

Note you should also ensure you use client side sorting. From the documentation

Server-side sorting only uses EntityField2 objects, so if the entity has a field which isn't a field mapped onto a table/view field, it's ignored in the server-side sorting actions because it's not part of the query send to the database. This is also true for fields mapped onto related fields. In these situations, use client-side sorting. 
pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 10-Jul-2007 08:17:48   

Ok... I will explain exact scenario..

I have a Grid, which is enabled with paging and sorting. It is connected with LLBLGenProDatasource2 and the LivePersistence is False.

Now, how do make the grid sort when the user click on the Header of the grid?

How do we get the selected sort expression from the grid in the PerformSelect Event?

Currently, we are storing the selected Column name in the Session and try to utilize it in the Permform Select?

Any better idea?

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 10-Jul-2007 09:25:17   

the field to be sorted would be found at run time only

The sort expression passed to the FetchEntityCollection method would try to sort the returned results on the database, creating an Order By clause.

Now if you are trying to sort on an entity property that's not mapped to a database field, you would need to sort on the client side. Using the Sort method of the entityCollection or by using Sort on an EntityView.

pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 12-Jul-2007 12:30:25   

Walaa wrote:

the field to be sorted would be found at run time only

The sort expression passed to the FetchEntityCollection method would try to sort the returned results on the database, creating an Order By clause.

Now if you are trying to sort on an entity property that's not mapped to a database field, you would need to sort on the client side. Using the Sort method of the entityCollection or by using Sort on an EntityView.

I guess it is non-LLBLGen Pro issue..... guide me If you can.

I am sorting a field that is mapped to a database field. The problem I am having is, how do we pass the sort field expression to the PerformSelect when the user clicks on the Grid's Header?

So that, I can pass that to the FetchEntityCollection method.

I appreciate any help I get.

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Jul-2007 14:47:05   

1- You should set the sortExpression of the bound column of the Grid to the corresponding field name. 2- Then when you click on the column header, this sort expression is sent to the LLBLGenProDataSource. 3- You should be able to access this sort expression in the PerformSelect event, by using e.Sorter, so you should pass this to the GetMulti() method as the sortExpression.