asp.net-web-api-odata

How to have two self-references in an entity class

為{幸葍}努か 提交于 2021-01-29 07:25:21
问题 I have a Foo that can have two optional references to itself: ParentId and RootId . public class Foo { [Key] public int FooId { get; set; } public int? ParentId { get; set; } [ForeignKey(nameof(ParentId))] public virtual Foo Parent { get; set; } public int? RootId { get; set; } [ForeignKey(nameof(RootId))] public virtual Foo RootFoo { get; set; } // ... } Having one works fine, but when I introduce the second self-reference I get error: Unable to determine the principal end of an association

How to get only Odata.Count without value

自作多情 提交于 2020-06-27 06:50:12
问题 Is there any way I can get only count of the data in response payload without any value array? I am using ODataV4.0 with Webapi 2.2. Currently it returns all the values and count when I query something like: http://odata/People?$count=true I just need something like "@odata.count":1, "value":[] or without "value" . Is the only way to have function for this job? 回答1: Set the $top to zero and $count to true. For example: http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$count=true

Applying Distinct to OData query

人走茶凉 提交于 2020-01-12 05:46:25
问题 I want to get a list of distinct values from my OData endpoint. But distinct or group by isn't supported yet. My URI query looks something like this GET /odata/Products?$select=foo & $top=10 & $count=true & distinct=true My Controller [EnableQuery] public IQueryable<FooBarBaz> Get(ODataQueryOptions<FooBarBaz> queryOptions, bool distinct) { //I've tried the following return Repository.AsQueryable().Distinct(); // and return Repository.AsQueryable().GroupBy(x => x.Foo); // and IQueryable query

How does one define an (optional) navigation property (?$expand=) in code?

会有一股神秘感。 提交于 2020-01-05 10:29:28
问题 First the explanation and the gist, then the question. So: Let's say I have a view AccountView defined in EF (6.1.1) database first (edmx) so that the code-generated class is //This class is generated from a view by EF (edmx)... public partial class AccountView { public System.Guid Id { get; set; } public int CompanyId { get; set; } } Then I create a partial class in the same namespace ( Entities ) as [MetadataType(typeof(AccounViewMetaData))] public partial class AccounView { //This is added

oData filter not working on navigation property with MongoDB and Web API

∥☆過路亽.° 提交于 2019-12-25 06:46:17
问题 Controller looks like public class NodesRestController : ODataController { private INodeService _nodeService; public NodesRestController(INodeService nodeService) { _nodeService = nodeService; } [EnableQuery()] public IQueryable<Node> Get() { return _nodeService.GetAllNodes(); } [EnableQuery()] public Node Get(string id) { return _nodeService.GetNodeById(id); } } in MongoDb repository i am returning AsQueryable of the collection. //..............Rest of initializations _collection =

Web api odata sending a long $filter string results in maxurlstring exceeds error

天大地大妈咪最大 提交于 2019-12-24 04:00:21
问题 I am trying to send a large $filter string to my webapi odata endpoint.But it gives me error saying the size of request headers are too long/maxurlstringlength exceeds. Is there a way to send the $filter in "POST" request and query the odata endpoint? i cannot use the batch statement as i am using .net framework 4.0. 来源: https://stackoverflow.com/questions/20187787/web-api-odata-sending-a-long-filter-string-results-in-maxurlstring-exceeds-erro

OData v4 error on start-up: Resource not found for the segment 'Whatever'

Deadly 提交于 2019-12-23 08:51:24
问题 I am building out my new v4 service and all was going well until I added a new controller for a new model/entity and got this error when starting the site up for a test run. The controller seems to be correctly coded, just like the others. The path template 'Customers' on the action 'GetFeed' in controller 'CustomersOData' is not a valid OData path template. Resource not found for the segment 'Customers'. What on Earth does that mean? 回答1: This error happens in Web API attribute routing

Get the OData catalog for Web API OData v4 in XML

。_饼干妹妹 提交于 2019-12-21 04:51:42
问题 I am trying to get a Web API OData V4 endpoint up and running. I got it going finally (after removing all the DateTime properties from my endpoint) and now the listing of the entities is in JSON. I love JSON, but I use LinqPad to test my endpoints. It does not understand the JSON for the listing of the entities that are in my feed. I have looked and can't seem to find a way to change this back to XML, so I am asking here. Is there a way to have the listing of entities for a Web API OData v4

Controlling what is returned with an $expand request

孤街醉人 提交于 2019-12-18 15:46:13
问题 So, using the ODataController , you get to control what gets returned if somebody does /odata/Foos(42)/Bars , because you'll be called on the FoosController like so: public IQueryable<Bar> GetBars([FromODataUri] int key) { } But what if you want to control what gets returned when somebody does /odata/Foos?$expand=Bars ? How do you deal with that? It triggers this method: public IQueryable<Foo> GetFoos() { } And I assume it just does an .Include("Bars") on the IQueryable<Foo> that you return,

How to get Web API OData v4 to use DateTime

与世无争的帅哥 提交于 2019-12-17 15:29:01
问题 I have a fairly large data model that I want to expose using Web API OData using the OData V4 protocol. The underlying data is stored in a SQL Server 2012 database. That database has many DateTime columns in it. As I was wiring it up I got an error that System.DateTime is not supported. So here is my question, what can I do to get my DateTime columns to be seen in the OData feed? NOTE: I am not able to go back and change all my columns to DateTimeOffset columns. I tried changing the type of