type system.linq.enumoblequery的对象无法转换为type system.collections.generic.ienumerab
我遇到了一个问题,可以在Web API上检索带有ODATA查询的XML数据类型,但是以JSON格式毫无问题。
错误这样说:
参数exception:类型'system.linq.enumoblequery
1 [microsoft.aspnetcore.odata.query.query.wrapper.selectsome
1 [odata_webapi.weatherforecast]] collections.generic.ienumerable`1 [odata_webapi.weatherforecast]'。
我只是在示例控制器 WeatherForecastController.cs
文件创建新的Web API项目时对其进行测试。
[HttpGet("GetWeatherForecast/{format}"), FormatFilter]
[EnableQuery]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
在没有ODATA查询的情况下检索XML数据类型效果很好,但是我希望它可以与ODATA查询一起使用,该怎么做?希望任何人都可以帮助我。
这起作用:
https://localhost:7110/WeatherForecast/GetWeatherForecast/xml
但不是这个
https://localhost:7110/WeatherForecast/GetWeatherForecast/xml?$select=Summary
I'm running into a problem retrieving XML datatype with OData Query on the Web API, but in JSON format there is no problem at all.
Error saying this :
ArgumentException: Object of type 'System.Linq.EnumerableQuery
1[Microsoft.AspNetCore.OData.Query.Wrapper.SelectSome
1[OData_WebAPI.WeatherForecast]]' cannot be converted to type 'System.Collections.Generic.IEnumerable`1[OData_WebAPI.WeatherForecast]'.
I'm just testing it on the sample Controller WeatherForecastController.cs
file when you create a new Web API project.
[HttpGet("GetWeatherForecast/{format}"), FormatFilter]
[EnableQuery]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
Retrieving XML datatype without OData Query works fine, but I want it to work with OData Query, How to do that? hoping anyone could help me.
This works :
https://localhost:7110/WeatherForecast/GetWeatherForecast/xml
But not this
https://localhost:7110/WeatherForecast/GetWeatherForecast/xml?$select=Summary
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论