我正在使用EntityDataSource并使用CommandText属性创建投影以跨多个表进行查询。我想允许分页,但是当我运行代码时,我得到一个错误,说
对于EntityDataSource,如果查询指定了投影和 启用分页,必须定义排序表达式。要么设置 OrderBy属性或将AutoGenerateOrderByClause设置为true
奇怪的是,我已将AutoGenerateOrderByClause设置为true,并且错误仍然存在。我不知道此时该做什么。这是我的示例EntityDataSource代码。
<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>
任何人都知道如何使用此工作进行分页?
答案 0 :(得分:4)
你有一个投射。要么摆脱SELECT,要么添加OrderBy =“it.astID”
答案 1 :(得分:1)
只是为了澄清AFD的接受答案。
将EntityDataSource更改为以下内容:
<asp:EntityDataSource runat="server" ID="EntityDataSource"
ConnectionString="name=AssetRegistryEntities"
DefaultContainerName="AssetRegistryEntities"
OrderBy="it.astID"
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>