接口过滤器 返回

SqlSugar 处理中
13 334

查询的时候加了全局过滤器

 db.QueryFilter.AddTableFilter<ITenantEntity>(it => it.TenantId.Equals(TenantId));

生成后的代码是:

SELECT COUNT(1) FROM [Web_Users]  WHERE ( 1 = 1 )   AND ( [IsDelete] = 0 )  AND  ([TenantId] = N'08d98e3b')


[SugarColumn(SqlParameterDbType = System.Data.DbType.AnsiString, SqlParameterSize = 50)]

public string TenantId { get; set; }


在接口对应的字段中加了 AnsiString 但是 查询的时候还是自动加了”N“,如果自动加了N,搜索速度会有影响怎么办?

热忱回答13

  • fate sta fate sta VIP0
    1个月前

    image.png


    要用这个方法打印

    string是nvarchar

    anisstring是varchar

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    在sql profiler 里面跟踪完整的语句是:  exec sp_executesql N'SELECT  [Id] AS [Id] , [ShopId] AS [ShopId] , [IntId] AS [IntId] , [Email] AS [Email] , [SaleUserId] AS [SaleUserId] , [SaleUserName] AS [SaleUserName] , [Nickname] AS [Nickname] , [UserName] AS [UserName] , [UserTypeid] AS [UserTypeid] , [Mobile] AS [Mobile] , [Tel] AS [Tel] , [RegistIP] AS [RegistIP] , [LoginIP] AS [LoginIP] , [IsEnabled] AS [IsEnabled] , [LoginTime] AS [LoginTime] , [RegistTime] AS [RegistTime] , [Remark] AS [Remark]  FROM [Web_Users]  WHERE ( 1 = 1 )   AND ( [IsDelete] = @IsDelete0 )  AND  ([TenantId] = @MethodConst1) ORDER BY CreateDate DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY',N'@IsDelete0 int,@MethodConst1 nvarchar(4000)',@IsDelete0=0,@MethodConst1=N'08d98e3b-153a-4759-856c-5df8dc57a7bd',如何去掉  ”N'08d98e3b-153a-4759-856c-5df8dc57a7bd'“中的N,如果去掉,测试了一下速度可以提高一倍。  

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    而且实际的字段类型是”varchar(50)“

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    sql:

    [Sql]:SELECT  [Id] AS [Id] , [ShopId] AS [ShopId] , [IntId] AS [IntId] , [Email] AS [Email] , [SaleUserId] AS [SaleUserId] , [SaleUserName] AS [SaleUserName] , [Nickname] AS [Nickname] , [UserName] AS [UserName] , [UserTypeid] AS [UserTypeid] , [Mobile] AS [Mobile] , [Tel] AS [Tel] , [RegistIP] AS [RegistIP] , [LoginIP] AS [LoginIP] , [IsEnabled] AS [IsEnabled] , [LoginTime] AS [LoginTime] , [RegistTime] AS [RegistTime] , [Remark] AS [Remark]  FROM [Web_Users]  WHERE ( 1 = 1 )   AND ( [IsDelete] = @IsDelete0 )  AND  ([TenantId] = @MethodConst1) ORDER BY CreateDate DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY

    [Pars]:

    [Name]:@IsDelete0 [Value]:0 [Type]:Int32

    [Name]:@MethodConst1 [Value]:08d98e3b-153a-4759-856c-5df8dc57a7bd [Type]:String

    打印输出是这样的,是不是加了N索引就没有了?

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    @fate sta:帮忙看一下怎么解决?

    0 回复
  • fate sta fate sta VIP0
    1个月前

    [SugarColumn(SqlParameterDbType = System.Data.DbType.AnsiString, SqlParameterSize = 50)]

    public string TenantId { get; set; }

    接口和实体都加了AnsiString 吗? 

    sqlsugar是不是最新。

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    @fate sta:都加了,sqlsugar最新的

    0 回复
  • fate sta fate sta VIP0
    1个月前

    好的 ,我这边验证一下

    0 回复
  • fate sta fate sta VIP0
    1个月前

    你先用等于试试,可能eauls没有处理到

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    不过这个实体是被继承的,应该没问题把

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    @fate sta:没错 就是Equals的问题

    0 回复
  • fate sta fate sta VIP0
    1个月前

    你先用等于,后面优化

    0 回复
  • 宏伟 宏伟 VIP0
    1个月前

    好的,谢谢。

    0 回复