.net-core - 带日期时间的 Odata V4
问题描述
嗨,我ODate
在比较日期时遇到问题。当我执行下一个请求时:
https://localhost:44391/api/v1/Invoice/OData?$top=11&$skip=0&$filter=InvoiceDate lt 2014-10-30
我得到下一个错误:
{
"StatusCode": 500,
"Message": "Unable to cast object of type 'Microsoft.OData.UriParser.ConvertNode' to type 'Microsoft.OData.UriParser.ConstantNode'."
}
我在数据库中的日期如下:
2013-12-30 00:00:00.000
2013-12-30 00:00:00.000
2017-07-14 00:00:00.000
在我的课Startup
上,我有下一个:
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
List<string> listaControllers = GetControllers();
foreach (string controller in listaControllers)
{
builder.EntitySet<BaseEntityDto>(controller);
}
return builder.GetEdmModel();
}
private static List<string> GetControllers()
{
Type parentType = typeof(ApiControllerBase<,,>);
Assembly assembly = Assembly.GetExecutingAssembly();
return assembly.GetTypes().Where(x => x.BaseType.Name == parentType.Name).Select(x => x.Name.Replace("Controller", "")).ToList<string>();
}
app.UseMvc(routeBuilder =>
{
routeBuilder.Expand().Select().Filter().Count().OrderBy().MaxTop(null);
routeBuilder.EnableDependencyInjection();
routeBuilder.MapODataServiceRoute("odata", "odata", GetEdmModel());
});
在我的实体中,Invoice.cs
我有下一个属性:
public DateTime InvoiceDate { get; set; }
当我在 Postman 中执行最后一个查询时,执行的控制器 ( Invoicecontroller.cs
) 是下一个:
[HttpGet("OData")]
public async Task<PageResult<InvoiceDto>> Get(ODataQueryOptions<InvoiceDto> queryOptions)
{
var options = new ODataQueryListOptions(queryOptions);
var result = await InvoiceQueryService.GetAll(options.QueryListOptions);
var count = await InvoiceQueryService.Count(options.QueryListOptions);
return new PageResult<InvoiceDto>(result, null, count);
}
我不知道问题出在哪里,我需要更多信息来解决问题。感谢大家试图解决这个问题。我想说我使用 Views no Tables。
解决方案
只把它放在我的实体中解决我的问题:
[Column(TypeName = "datetime")]
public DateTime InvoiceDate { get; set; }
感谢所有社区阅读我的问题。
推荐阅读
- c# - 如何在 asp.net 网站/页面上的映射驱动器中读取文件
- c++ - 如何在 C++/C 代码中执行多个 gnuplot 命令
- java - 在不使用 BorderPane 的情况下设置节点的对齐方式?
- amazon-web-services - AWS Sagemaker 是否对 PIPE 模式下的 S3 流数据收费(用于模型训练)?
- batch-file - 批量超时命令
- python - 如何加快这个 numpy.arange 循环?
- javascript - JS - 从 DOM 访问 a(错误:“TypeError: tablex[0] is undefined”)
我想将
<th>
标头添加到一个<table>
没有一个"id"
但在<div>
一个已知的中"id"
,所以我遍历 DOM 来找到它:// search <table&
- python - 如何修复“无法使用形状为 [1000] 的张量更新形状为 [] 的变量,形状必须相等。” keras LSTM网络中的错误?
- ruby - Mitmdump 不适用于 selenium-webDriver
- rust - 如何获取与柴油的关联