我正在尝试使用 DateTimeOffset 列上的谓词查询我的实体,但从 Breeze.WebApi 获得 500 错误响应。错误信息是
Unable to perform operation: leon types:System.Nullable`1[System.DateTimeOffset], System.DateTime
我看到产生的uri类似于
http://localhost:49800/api/Breeze Orders?$filter=LocalDateTime%20le%20datetime'2013-03-03T00%3A00%3A00.000Z'
什么工作:
- 我可以查询其他日期时间、文本列
- 我可以将新数据保存到我的“LocalDateTime”字段中
查询的完整错误响应是:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Unable to perform operation: leon types:System.Nullable`1[System.DateTimeOffset], System.DateTime
</ExceptionMessage>
<ExceptionType>System.Exception</ExceptionType>
<StackTrace>
at Breeze.WebApi.ParseTreeVisitor.CoerceTypes(String operatorName, Expression& leftExpr, Expression& rightExpr) at Breeze.WebApi.ParseTreeVisitor.VisitBinary(ParseTreeNode node, String operatorName, Expression leftExpr, Expression rightExpr) at Breeze.WebApi.ParseTreeVisitor.VisitNode(ParseTreeNode node) at Breeze.WebApi.ParseTreeVisitor.Parse(Type rootType, ParseTreeNode node) at Breeze.WebApi.ExpressionTreeBuilder.Parse(Type rootType, String source) at Breeze.WebApi.ODataActionFilter.BuildFilterFunc(String filterQueryString, Type elementType) at Breeze.WebApi.ODataActionFilter.OnActionExecuted(HttpActionExecutedContext actionExecutedContext) at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception) at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response) at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t) at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)
</StackTrace>
</Error>
.
编辑
到达那里,但不完全。安装 Breeze 1.2.8 后,客户端现在生成正确类型的 uri,例如
http://localhost:49800/api/Breeze/Orders?$filter=LocalDateTime%20ge%20datetimeoffset'2013-01-01T11%3A00%3A00.000Z'
在我的情况下,不需要使用 setEntityTypeForResourceName 来修复实体类型。上面的uri仍然给我错误:
Unable to perform operation: leon types:System.Nullable`1[System.DateTimeOffset], System.DateTimeOffset
从更改我的服务器端模型
public Nullable<System.DateTimeOffset> LocalDateTime { get; set; }
至
public System.DateTimeOffset LocalDateTime { get; set; }
允许我的 uri 工作。那么我们能否修复可为空的 DateTimeOffset。