Consider the following method in a Web Api controller:
[Queryable(AllowedQueryOptions= AllowedQueryOptions.All)] public override IQueryable<Mandate> Get() { return new List<Mandate>() { new Mandate() { Id = 1, PolicyNumber = "350000000", OpenPositions = new List<OpenPosition>(){ new OpenPosition(){ Id = 1, Amount =2300 }, new OpenPosition(){ Id = 2, Amount =2100 } }}, new Mandate() { Id = 2, PolicyNumber = "240000000" , OpenPositions = new List<OpenPosition>(){ new OpenPosition(){ Id = 3, Amount =2500 }, new OpenPosition(){ Id = 2, Amount =2100 } } } }.AsQueryable<Mandate>(); }
Here the list is created manually and if I look at the following URL:
http://localhost:52446/odata/Mandates?$filter=Id eq 1 it returns the correct item from the list.
Now, obviously, the list is likely to be a database structure. Data will be retrieved using some ORM and returned to the web API service.
I do not use Entity Framework (and cannot because of outdated systems).
How can I use the web api in this case? How would I translate the url parameters so that the filters are applied by the layer responsible for data access?
odata asp.net-web-api
Sam
source share