How to sorting by a related field when use LLBLDS?

Posts   
 
    
xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 12-Dec-2006 07:57:47   

When set a GridView control bind to a LLBLDataSource,Sorting by normal fields is OK,such as by ID,and so on. But When I Sort by a relation field,it doesn't work.

For example,the LLBLDS's EntityCollectionTypeName is "EmployeeCollection",when sort by EmployeeId,it's OK.But when sort by DepartmentName which is a relation field--this field has not problem,because I can select it from a dropdownlist of the GridView's column design window---It seems that it doesn't work.

Please help me, thank u.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Dec-2006 08:33:03   

Please provide more details:

What's the runtimeLibrary version that you are using? Are you using Adapter or SelfServicing? In case of Adapter, have you used prefetchPaths to fetch the related entity?

Please refer to the following thread for guidelines: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7720

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Dec-2006 10:49:04   

Also, you mapped the DepartmentName in the EmployeeEntity as a field mapped on a related field (in department) ?

Anyway, I have the suspicion you're using Selfservicing, so in your code behind, in the PageLoad event handler, set the datasource's RelationsToUse property and the SorterToUse to the proper relation collection and sort expression to sort on the database when fetching data.

Do you use sorting triggered by a gridview column click?

Frans Bouma | Lead developer LLBLGen Pro
dbircsak
User
Posts: 7
Joined: 22-Dec-2006
# Posted on: 22-Dec-2006 01:48:36   

I'm having the same problem.. which even prompted me to register on here... simple_smile

I am using SelfServicing, run time 2.0.50727...

My GridView points to an LLBLGenProDataSource... and I have a column like this:

        <asp:TemplateField HeaderText="Email">
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# ((MyEntity)Container.DataItem).Contact.Email %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

I can't set SortExpression="Email", right? I thought maybe setting up relationToUse to include MyEntity's relation with Contact table.. that I could then set SortExpression to "Contact.Email" ? but that doesn't make sense. I tried to capture the OnSorting event and if the user picked e.SortExpression = "Email" then I would set sorterToUse for the LLBLGenProDataSource to Email field... but this didn't work either. cry

Thanks for the assistance!

Darrell

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Dec-2006 08:59:31   

Please don't use older threads, instead create your new one. And 2.0.50727 is not a runtime Library version, please check the following guidelines thread for more details: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7720

You will need to add a "field mapped on related field", and use PrefetchPath to fetch the related entity along with the main entity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 22-Dec-2006 10:41:37   

As Walaa said, a field mapped onto a related field helps here, you then will have a field in the entity you're binding to the grid which you can sort on (client side). Set the sorting mode of the datasourcecontrol to Client. you can also sort server-side, do you want to sort server side when the data is fetched or client side in the grid (so not going back to the db) ?

Frans Bouma | Lead developer LLBLGen Pro