当我查询 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 警报。
最佳答案
使用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/