WebAPI ODATA without Entity Framework

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?

+7
odata asp.net-web-api
source share
1 answer

Got it. You pointed me in the right direction with your LINQ provider. I found out that I can do this easily with the ORM we use (OpenAccess). More details here: http://docs.telerik.com/data-access/developers-guide/using-web-services/asp.net-web-api/developer-guide-wcfservices-web-api-expose-oacontext

0
source share

All Articles