ServiceStack AutoQuery 关于丢失属性的警告

标签 servicestack servicestack-autoquery

当我查询 AutoQuery 服务(常规 GET 请求)时,即使请求工作正常,我也会在日志中收到警告。对于 URL:https://localhost:5001/employees?BirthDate%3E=1950-01-01,警告如下所示

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 GET https://localhost:5001/employees?BirthDate%3E=1950-01-01 - -
warn: ServiceStack.Serialization.StringMapTypeDeserializer[0]
      Property 'birthdate>' does not exist on type 'autoquery.ServiceModel.AutoQueries+QueryEmployee'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/2 GET https://localhost:5001/employees?BirthDate%3E=1950-01-01 - - - 200 - text/html 291.5297ms

我使用 Northwind 数据库创建了一个示例,该数据库是通过 x mix northwind.sqlite 获得的和来自官方示例的 DTO:https://github.com/ServiceStackApps/Northwind/blob/master/src/Northwind/Northwind.ServiceModel/Types/Employee.cs .

这个“错误警告”有点麻烦,因为没有任何问题,而且它在我的日志中填满了我需要忽略的警告。特别是因为我在日志中设置了 WARN+ERR 警报。

我在这里工作示例:https://github.com/specimen151/autoquerywarning

最佳答案

使用AutoQuery's Implicit Contentions时这是预期的由于请求发送到 API 时没有匹配的请求 DTO 属性,因此会记录警告。

您可以将 BirthDate 添加为 AutoQuery DTO 的类型化属性,也可以使用以下方法忽略所有“BirthDate”属性:

SetConfig(new HostConfig {
    IgnoreWarningsOnPropertyNames = { "BirthDate" }
});

或者您可以通过以下方式禁用所有丢失的属性警告:

SetConfig(new HostConfig {
    IgnoreWarningsOnAllProperties = true
});

在最新的 v5.12.1 中,现在是 available on MyGet默认情况下,ServiceStack 将不再警告 AutoQuery DTO 上缺少属性,可以通过以下方式重新启用它:

SetConfig(new HostConfig {
    IgnoreWarningsOnAutoQueryApis = false
});

关于ServiceStack AutoQuery 关于丢失属性的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68920127/

相关文章:

servicestack - 需要 AutoQuery 洞察力

ServiceStack AutoQuery 和 [Authenticate] 属性

c# - ServiceStack - 强制为某些类生成 Typescript 类型

servicestack - 为什么servicestack服务路由到GET而不是PUT

json - 如何将 F# Union 类型与 Servicestack JSON 序列化结合使用?

servicestack - 在 MonoDevelop 中使用特定版本的包

c# - 服务堆栈 :How to get StatusCode from JsonServiceClient Get method

ServiceStack - 域和子域的身份验证