关于OrderByIF排序问题 返回

SqlSugar
8 82

image.png根据前端传送的排序字段和排序方式,但排序没有效果,生成的sql不对

exec sp_executesql N'SELECT * FROM (SELECT  [a].[F_Id] AS [id] , [a].[NI001] AS [ni001] , [a].[NI002] AS [ni002] , [a].[NI003] AS [ni003] , [a].[NI004] AS [ni004] , [a].[NI005] AS [ni005] , [a].[F_CreatorTime] AS [creatorTime] , [a].[F_CreatorUserId] AS [creatorUserId] , [b].[F_FLOWID] AS [flowId] , [b].[F_STATUS] AS [flowState] ,ROW_NUMBER() OVER(ORDER BY (( @Const0 + @sidx1 ) +  @Const2 ) ASC) AS RowIndex  FROM [test_CMSNI] a Left JOIN [FLOW_TASK] b ON ( [a].[F_Id] = [b].[F_Id] )  ) T WHERE RowIndex BETWEEN 1 AND 20',N'@Const0 nvarchar(4000),@sidx1 nvarchar(4000),@Const2 nvarchar(4000)',@Const0=N'ni004',@sidx1=N' ',@Const2=N'desc',麻烦各位看官!

热忱回答8

  • orderby写在select后面一定要加 MergeTable()

    0 回复
  • 推荐写到前面

    0 回复
  • @fate sta:你好,写在前面也没有效果,因为这样子生成出来的sql是这样子的,exec sp_executesql N'SELECT * FROM (SELECT  [a].[F_Id] AS [id] , [a].[NI001] AS [ni001] , [a].[NI002] AS [ni002] , [a].[NI003] AS [ni003] , [a].[NI004] AS [ni004] , [a].[NI005] AS [ni005] , [a].[F_CreatorTime] AS [creatorTime] , [a].[F_CreatorUserId] AS [creatorUserId] , [b].[F_FLOWID] AS [flowId] , [b].[F_STATUS] AS [flowState] ,ROW_NUMBER() OVER(ORDER BY (( @Const0 + @sidx1 ) +  @Const2 ) ASC) AS RowIndex  FROM [test_CMSNI] a Left JOIN [FLOW_TASK] b ON ( [a].[F_Id] = [b].[F_Id] )  ) T WHERE RowIndex BETWEEN 1 AND 20',N'@Const0 nvarchar(4000),@sidx1 nvarchar(4000),@Const2 nvarchar(4000)',@Const0=N'ni001',@sidx1=N' ',@Const2=N'desc'image.png

    0 回复
  • a=>去掉

    0 回复
  • OrderBy(字符串)不应该有表达式

    0 回复
  • @fate sta:.OrderByIF(),反编译是这样子的 new ISugarQueryable<T, T2> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc);所以第一个参数传表达式应该没有问题呀

    0 回复
  • @中律十六C:那就是缺少重载了,你写到select后面吧

    0 回复
  •  OrderByIF(bool,string) 应该是用这个重载

    0 回复