Search code examples
asp.netentity-framework-4

Paging error with EntityDataSource


I'm using an EntityDataSource and creating a projection using the CommandText property to query across several tables. I want to allow paging, but when I run the code I get an error that says

For the EntityDataSource, if the query specifies a projection and paging is enabled, a sort expression must be defined. Either set the OrderBy property or set AutoGenerateOrderByClause to true

Odd thing is, I HAVE set the AutoGenerateOrderByClause to true and the error persists. I'm not sure what to do at this point. Here's my example EntityDataSource code.

<asp:EntityDataSource runat="server" ID="EntityDataSource"
    ConnectionString="name=AssetRegistryEntities" 
    DefaultContainerName="AssetRegistryEntities"
    CommandText="SELECT a.astName, a.astDescription, r.rolFK_adCN 
                 FROM AssetRegistryEntities.Assets as a
                 JOIN AssetRegistryEntities.Roles as r ON r.rolFK_astID = a.astID
                 WHERE r.rolFK_adCN = 'dpellerin'
                 AND r.rolTypeCode = 'PRIANALYST'"
     AutoGenerateOrderByClause="true">
</asp:EntityDataSource>

Anyone know how to make paging work with this?


Solution

  • You have a projection. Either get rid of the SELECT or also add OrderBy="it.astID"