Sorting using LLBLGenProDataSource and "fields on related fields"

Posts   
 
    
Koolworld
User
Posts: 50
Joined: 10-Oct-2006
# Posted on: 27-Nov-2006 14:47:39   

Hi, im trying to figure out sort the collection from a LLBLGenProDataSource which is placed in the .aspx and has LivePersistence set to false and SortingMode set to client side:

<llblgenpro:LLBLGenProDataSource ID="LLBLGenProDataSource1" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="oeg_intranet.CollectionClasses.CompaniesCollection, oeg_intranet" SortingMode="ClientSide" LivePersistence="False"> </llblgenpro:LLBLGenProDataSource>

in the code behind i have the PerformSelect:

Protected Sub LLBLGenProDataSourceCompanies_PerformSelect(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs) Handles LLBLGenProDataSource1.PerformSelect 'Sort Dim sortExpression As New SortExpression sortExpression.Add(New SortClause(CompaniesFields.CompanyName, SortOperator.Ascending)) e.ContainedCollection.GetMulti(e.Filter, -1, sortExpression, e.Relations, e.PrefetchPath) End Sub

This works fine, but i want to also be able to set the sorting to a "Fields on related fields" field which i created in LLBLGen but it doesn't appear as a field of "CompaniesFields". What's the best way to do this and is there a simpler way of doing this?

I want to be able to pass the sortby field name in via the querystring and then set the sort expression from this.

Thanks in advance.

Dan.

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 27-Nov-2006 15:33:34   

Hello,

did you try to use your field in other case than filtering to be sure that it is generated?

Koolworld
User
Posts: 50
Joined: 10-Oct-2006
# Posted on: 27-Nov-2006 16:00:51   

Hi, i can see the "fields on related fields" if i create that entity:

Dim objCompany As New CompaniesEntity Dim strSector As String = objCompany.SectorName

and i can access them in the aspx gridview using:

<asp:TemplateField HeaderText="Sector" SortExpression="SectorName"> <ItemTemplate> <asp:Label ID="lblSectorName" runat="server" Text='<%# Eval("SectorName") %>'></asp:Label> </ItemTemplate> </asp:TemplateField>

but they don't appear in the CompaniesFields.[fieldname] list. Can i do this another way without using EntityFields, maybe create the "fieldname" on the fly from what is passed in from the querystring?

Thanks.

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 27-Nov-2006 16:44:13   

Hello,

sectorname is not really a field of Company so it will not appears in CompaniesFields. Behind the call of sectorName property, it will create the related entity if doesn't exist and set or get the value from the related entity. If you want to create a sorted clause on the sectorName Field you have to do this using the related table and be sure that the relation between Company and your other table exists.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 27-Nov-2006 17:04:30   

To sort on the client side, you can use a SortClause, and use new EntityProperty("FieldName") instead of EntityNameFields.FieldName

This only works with sorting on client side so the sorter is executed on the view.

Frans Bouma | Lead developer LLBLGen Pro
Koolworld
User
Posts: 50
Joined: 10-Oct-2006
# Posted on: 27-Nov-2006 17:16:28   

Thanks for the help so far. If i use the EntityProperty, as im using client side sorting, i try this:

Protected Sub LLBLGenProDataSourceCompanies_PerformSelect(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs) Handles LLBLGenProDataSource1.PerformSelect 'Sort Dim sortExpression As New SortExpression sortExpression.Add(New SortClause(New EntityProperty("SectorName"), Nothing, SortOperator.Ascending)) e.ContainedCollection.GetMulti(e.Filter, -1, sortExpression, e.Relations, e.PrefetchPath) End Sub

but i get:

"System.Exception: The method or operation is not implemented." on the GetMulti line.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 27-Nov-2006 17:52:33   

Yes, that's understandable: that;s a db call and then you should jbb's advice.

When you set the sorter on the datasourcecontrol and set the datasourcecontrol to clientside sorting, then you can use a sortclause/expression with EntityProperty simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Koolworld
User
Posts: 50
Joined: 10-Oct-2006
# Posted on: 27-Nov-2006 20:05:51   

Im getting more confused here. I have set the Datasource to clientside sorting via the aspx control code as shown on the first message of this thread.

Do you have examples of what i need to do as i don't really understand what you are trying to tell me.

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 27-Nov-2006 20:53:40   

Koolworld wrote:

Im getting more confused here. I have set the Datasource to clientside sorting via the aspx control code as shown on the first message of this thread.

Do you have examples of what i need to do as i don't really understand what you are trying to tell me. Thanks.

Your performselect handler fetches data, using the GetMulti call. Now, that data is an entity collection and if the datasource control has its SorterToUse set to a SortExpression AND you've set sortingmode to clientside, the entitycollection is sorted using that sortexpression right before the data is handed over to the bound control, e.g. a grid.

So the sortexpression specified for the GetMulti call is used for the query executed on the database, effectively meaning 'server side' sorting. The sortexpression you set on the datasourcecontrol is used for client-side sorting if you're using the sortingmode 'client side'.

To sort on a related field, you can do that on the server, as jbb said, or you can do that on the client. to do it on the client, you thus don't specify a sortexpression with the getmulti call, but set the datasourcecontrol's SorterTouse to that SortExpression.

Frans Bouma | Lead developer LLBLGen Pro
Koolworld
User
Posts: 50
Joined: 10-Oct-2006
# Posted on: 27-Nov-2006 21:13:00   

i see, that makes sense! seems to be working ok now so thanks for your help!