Hi Daelmo,
Yes, I'm quite certain I have a field mapped on related field.
As I mention at the top, 2.6 (final), self-servicing.
To be absolutely certain the issue was with LLBLGen and not Telerik, I put together the simplest possible project using Northwind and a GridView plus the LLBLGenProDataSource control.
I added two entites: Orders and Customers.
On the Orders entity, I created a field mapped on related field pointing to the "Customers.CompanyName" field. I renamed field to be "Company" to have the a simalar situation as my real project.
Generated the project.
Bound the LLBLGenProDataSource to the OrdersCollection.
Bound the GridView to the LLBLGenProDataSource.
Enabled paging and sorting on the GridView.
Enabled paging and set SortingMode="ServerSide" on the LLBLGenProDataSource.
The ASPX code:
<asp:GridView ID="GridView1" runat="server"
DataSourceID="LLBLGenProDataSource1"
AllowPaging="True" AllowSorting="true"
AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="OrderId"
ForeColor="#333333" GridLines="None">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="OrderId" HeaderText="OrderId" InsertVisible="False" ReadOnly="True" SortExpression="OrderId" />
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId" SortExpression="CustomerId" />
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate" SortExpression="OrderDate" />
<asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<llblgenpro:LLBLGenProDataSource ID="LLBLGenProDataSource1" runat="server"
DataContainerType="EntityCollection"
EntityCollectionTypeName="Northwind.Data.CollectionClasses.OrdersCollection, Northwind.Data"
EnablePaging="true"
SortingMode="ServerSide">
</llblgenpro:LLBLGenProDataSource>
Added the following code in code behind:
LLBLGenProDataSource1.RelationsToUse = new RelationCollection();
LLBLGenProDataSource1.RelationsToUse.Add(OrdersEntity.Relations.CustomersEntityUsingCustomerId);
IPrefetchPath path = new PrefetchPath((int)EntityType.OrdersEntity);
path.Add(OrdersEntity.PrefetchPathCustomers);
LLBLGenProDataSource1.PrefetchPathToUse = path;
Ran it. Same problem. This is the SQL emitted:
SELECT TOP 10
[Northwind].[dbo].[Orders].[OrderID] AS [OrderId],
[Northwind].[dbo].[Orders].[CustomerID] AS [CustomerId],
[Northwind].[dbo].[Orders].[EmployeeID] AS [EmployeeId],
[Northwind].[dbo].[Orders].[OrderDate],
[Northwind].[dbo].[Orders].[RequiredDate],
[Northwind].[dbo].[Orders].[ShippedDate],
[Northwind].[dbo].[Orders].[ShipVia],
[Northwind].[dbo].[Orders].[Freight],
[Northwind].[dbo].[Orders].[ShipName],
[Northwind].[dbo].[Orders].[ShipAddress],
[Northwind].[dbo].[Orders].[ShipCity],
[Northwind].[dbo].[Orders].[ShipRegion],
[Northwind].[dbo].[Orders].[ShipPostalCode],
[Northwind].[dbo].[Orders].[ShipCountry]
FROM (
[Northwind].[dbo].[Customers]
INNER JOIN [Northwind].[dbo].[Orders] ON [Northwind].[dbo].[Customers].[CustomerID]=[Northwind].[dbo].[Orders].[CustomerID]
)
ORDER BY Company ASC
SQL Server rightly complains that there is no column named "Company".
I found that I can get this to work by changing the SortExpression on the GridView to "CompanyName". Hacky, but ok in this instance.
I found that it does NOT work if I fully qualify it: "Customers.CompanyName". This would work fine in the sql itself, but doesn't work when fed in thru the grid and data control.
This means that it will not work for my real project since the column names on both the main and related tables are the same ("Title").
So I guess my question is:
How do I get sorting to work on SELF-SERVICE when the underlying column name on a field mapped on related field is the same as a column name in the base entity?