asp.net-web-api-odata

WebApi EntitySetController using composite keys

不羁的心 提交于 2019-12-13 05:01:51
问题 The excellent sample code: Support Composite Key in ASP.NET Web API OData illustrates how to create routing conventions to make WebApi OData work with composite keys. However it is using ODataController (as one of the unanswered discussions on the sample code mentions) which I presume has many downsides (which I am yet to fully uncover)... has anyone created an example using the benefits of EntitySetController? 回答1: Going forward the recommended approach is to directly derive from

Expanding collections using Web Api OData controller

时光总嘲笑我的痴心妄想 提交于 2019-12-12 06:37:44
问题 I'm using OData framework 5.0.0 and Web API 5.0.0 and EntityFramework 5.0.0. And have problem with expand on navigation property which is a collection. I always get the following exception: The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'. The given key was not present in the dictionary. at System.Web.Http.OData.Query.Expressions.SelectExpandWrapper`1.GetEdmType() at System.Web.Http.OData.Formatter.Serialization

OData query option $count in $expand not working

旧城冷巷雨未停 提交于 2019-12-12 01:55:23
问题 I tried to use $count in an $expand like this query .../OData/Foo(1)?$expand=Bars($count=true) However count is no where to be found in the result. { "...": "...", "Bars": { "...": "..." } } No error either. I'm using ASP.NET Web API OData 5.4, which is using OData v4. What gives? Not implemented yet? 回答1: This feature hasn't been implemented yet. A related issue has been created https://github.com/OData/WebApi/issues/165 . 来源: https://stackoverflow.com/questions/28967908/odata-query-option

EntityFramework Model-First metadata for breezejs

蹲街弑〆低调 提交于 2019-12-11 13:20:19
问题 Breeze.js library requires metadata of the entity context. Web API OData has a default ODataConventionModelBuilder for this operation, but doesn't work for Breeze, since it lacks foreign key information. Thus, Breeze offers a special package called "EdmBuilder" to generate this information. However, it only works with Code-First approach. If there is an existing edmx file, it gives the following exception; Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database

POST to a related collection in WEB API 2 with OData 4

我们两清 提交于 2019-12-10 17:22:39
问题 I want to have a route like: /Accounts(id)/Orders where I can execute a POST to create an order. I can't find a way to add this route using OData in WebApi. For GET there is a convention to follow to get related collections, but I am not able to find any convention for posting new entities to a related collection. Is there a standard way to handle this POST request with Web API 2 and OData 4 ? 回答1: Added the following attributes to the method and it worked: [HttpPost] [ODataRoute("Accounts(

OData Exception The limit of '0' for Top query has been exceeded

天涯浪子 提交于 2019-12-10 12:29:44
问题 I am using OData Web API for Version 4, when I try to query OData web Api using $top parameter, it return me following exception message. The query specified in the URI is not valid. The limit of '0' for Top query has been exceeded. The value from the incoming request is '10' I am using Apache Ignite dotNet LINQ as data source instead of Entity Framework, my OData controller action method is as follows: [EnableQuery] public IQueryable<Productioncurvepnl> GetProductioncurvepnl() { Console

Translate OData queries to SQL

旧城冷巷雨未停 提交于 2019-12-10 11:15:11
问题 I'm in an ODataController and I have an ODataQueryOptions (and all the rest of it). I know that the source of the data is a table in SQL Server. However, my EF model (that was used by the WEB API framework to route the HTTP request to my controller) is typeless, i.e., I don't have a POCO class. Normally -- if I did have a POCO class -- the framework would magically write SQL from the OData query so that the paging, filtering, and sorting is done on the database and not in memory on the web

The path template on the action in controller is not a valid OData path template

北战南征 提交于 2019-12-10 01:59:15
问题 I am getting the following error: The path template 'GetClients()' on the action 'GetClients' in controller 'Clients' is not a valid OData path template. Resource not found for the segment 'GetClients'. My controller method looks like this public class ClientsController : ODataController { [HttpGet] [ODataRoute("GetClients(Id={Id})")] public IHttpActionResult GetClients([FromODataUri] int Id) { return Ok(_clientsRepository.GetClients(Id)); } } My WebAPIConfig file has builder.EntityType

The complex type 'MyData.AssetReading' refers to the entity type 'MyData.Asset' through the property 'Asset'

自闭症网瘾萝莉.ら 提交于 2019-12-10 00:10:47
问题 Looking at setting up Web API odata and trying to expose the data out of our edmx to it. The problem is that every time i add an entity to the OdataConventionBuilder I get a big nasty error message on load saying: The complex type 'MyData.AssetReading' refers to the entity type 'MyData.Asset' through the property 'Asset' It seems for relations defined in the edmx is bombing the webapi odata out about a complex type. Any ideas on how to get around this as the edmx is huge and a rejig of it is

Can't save the data to OData controller after updating to Microsoft.AspNet.WebApi.OData 5.3.x

谁都会走 提交于 2019-12-08 12:17:30
问题 Not sure what's changed exactly and causing this partial error (since it's not happening with retrieving the data) but after updating Microsoft.AspNet.WebApi.OData library to 5.3.x version, breeze has an issue with saving the data to OData controller. It's about the urls of the batch requests. It can be reproduced with breeze's its own sample OData project as well; http://www.breezejs.com/samples/breeze-web-api-odata If you look at ExecuteRequestMessagesAsync method of the BatchHandler class,