2

当我查询 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/员工.cs

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

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

4

1 回答 1

2

这在使用AutoQuery 的隐式争用时会出现这种情况,因为请求被发送到 API 时没有匹配的请求 DTO 属性,所以会记录警告。

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

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

或者,您可以使用以下方法禁用所有缺少的属性警告:

SetConfig(new HostConfig {
    IgnoreWarningsOnAllProperties = true
});

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

SetConfig(new HostConfig {
    IgnoreWarningsOnAutoQueryApis = false
});
于 2021-08-25T09:43:02.257 回答