【发布时间】:2015-03-20 04:18:30
【问题描述】:
我有一个使用自动查询的 ServiceStack 服务,其中忽略大于或小于的 DateTime。
这是我的请求 DTO:
public class GetSources : QueryBase<DbSource, Source>
{
public string Name { get; set; }
public string NameContains { get; set; }
public string NameStartsWith { get; set; }
public DateTime? LastUpdatedDateGreaterThan { get; set; }
public DateTime? LastUpdatedDateLessThan { get; set; }
}
ormlite T4模板生成的数据库表poco如下所示:
[Alias("DbSources")]
[Schema("SomeSchema")]
public partial class DbSource
{
[AutoIncrement]
public int Id { get; set;}
[Required]
public string Name { get; set;}
[Required]
public DateTime LastUpdatedDate { get; set;}
}
在服务中我做了一些验证,然后像这样使用 AutoQuery:
var q = AutoQuery.CreateQuery(dto, Request.GetRequestParams());
q.Join<DbSource, CompanySource>((source, companySource) => source.Id == companySource.SourceId && companySource.CompanyID == companyId);
return AutoQuery.Execute(dto, q);
我正在使用 mstest
[TestMethod]
public void GetSources_LastUpdatedGreaterThan()
{
var expected = DateTime.Now;
var query = new GetSources { LastUpdatedDateGreaterThan = expected};
QueryResponse<Source> result;
using (var service = appHost.Container.Resolve<SourceService>())
{
service.Request = new MockHttpRequest();
result = service.Any(query);
}
log.Info(result.ToJson());
result.Results.ForEach(src => Assert.IsTrue(src.LastUpdatedDate > expected));
}
Name、NameContains 和 NameStartsWith 在其他测试中都按预期工作,但 LastUpdatedDateGreaterThan 和 LastUpdatedDateLessThan 都不会生成 where 子句。在我的 AutoQuery 设置中,所有属性都是默认值,但 EnableUntypedQueries 为 false。
我知道我可以在服务中明确添加它们的位置。即
q.Where(source => source.LastUpdatedDate > dto.LastUpdatedDateGreaterThan);
但如果可能的话,我希望 AutoQuery 能够处理它。 DateTime 是否适用于 AutoQuery?还是我在代码中做错了什么。
【问题讨论】:
-
你能把一个独立的 repro 放在一起吗(例如在 github repo 或 gist 中),因为我无法 repro any issues using DateTime with AutoQuery。
标签: servicestack ormlite-servicestack