How to use OData without Entity Framework

I am interested in creating a wcf OData data service using visual studio 2012. However, I do not want to use an entity model structure, but rather use my schema less than the nosql dataset to store and retrieve data. Is there a way that allows me to take control of odata services without delving into a specific class structure, such as the Microsoft entity infrastructure.

+4
source share
1 answer

You can use the Microsoft OData implementation without the Entity Framework. You need an implementation of IQueryable . Here is an example of an OData service requesting an array of objects:

 using System.Web.Http; using System.Web.Http.OData; using System.Web.Http.OData.Builder; using System.Web.Http.OData.Query; // GET api/values [ActionName("FromList")] public IList<Poco> GetFromList(ODataQueryOptions<Poco> queryOptions) { IQueryable<Poco> data = ( new Poco[] { new Poco() { id = 1, name = "one", type = "a" }, new Poco() { id = 2, name = "two", type = "b" }, new Poco() { id = 3, name = "three", type = "c" } }) .AsQueryable(); var t = new ODataValidationSettings() { MaxTop = 25 }; queryOptions.Validate(t); var s = new ODataQuerySettings() { PageSize = 25 }; IEnumerable<Poco> results = (IEnumerable<Poco>)queryOptions.ApplyTo(data, s); return results.ToList(); } public class Poco { public int id { get; set; } public string name { get; set; } public string type { get; set; } } 
+4
source

Source: https://habr.com/ru/post/1482342/


All Articles