Reputation: 4305
I am interested in creating a OData wcf data service using visual studio 2012. However I do not want to use an entity model framework but rather use my scheme less nosql dataset to store and retrieve the data. Is there a way that allows me to take control of the odata services without being tide into a specific class structure such as Microsoft's entity framework.
Upvotes: 4
Views: 2056
Reputation: 14580
You can use the Microsoft OData implementation without the Entity Framework. What you do need is an implementation of IQueryable
. Here's an example OData service querying 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; }
}
Upvotes: 4