PetaPoco中使用分页方法时遇到用DISTINCT去重时,要注意排序字段的SQL表别名写法。
作者:互联网
//排序-根据实际情况修改,注意这里不要指定a.的别名,不然会造成PageList方法的错误找不到排序列
//sql.OrderBy("a.CreateTime Desc");
//sql.OrderBy("a.Id");
sql.OrderBy("CreateTime Desc");
sql.OrderBy("Id");
response = await repository.PageList
不然会提示
返回时会异常
- Message:无法绑定由多个部分组成的标识符 "a.CreateTime"。
无法绑定由多个部分组成的标识符 "a.Id"。
用MSSQL追踪代码转换后执行的结果
exec sp_executesql N'SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY a.CreateTime Desc
, a.Id) peta_rn, peta_inner.* FROM (SELECT DISTINCT a.*
FROM Sales_Order_Exchange a
LEFT JOIN Sales_Order_Exchange_Detail b
ON a.Id=b.OrderId
WHERE (a.ShopId=''b6fa1418-82fb-4ad3-9445-2bdc1b667981'')
AND (a.IsDel=0)
) peta_inner) peta_paged WHERE peta_rn > @0 AND peta_rn <= @1',N'@0 bigint,@1 bigint',@0=0,@1=10
上面报错a.CreateTime,因为是用Peta框架自动生成了别名peta_inner
标签:OrderBy,peta,DISTINCT,SQL,Id,重时,sql,CreateTime,SELECT 来源: https://www.cnblogs.com/hmfl/p/15579046.html