Open Data (OData)

Breeze can consume any standard OData feed “as is” when you configure the client for OData:

    dataService: "OData", ...

This Breeze client will retrieve standard OData metadata, submit standard OData query requests, and interpret the results as Breeze entities. 

The Breeze OData adapter depends upon datajs to handle lower level communications with OData sources. Be sure to include that script before Breeze.js itself.

ASP.NET Web API OData Service

We highly recommend the Pluralsight course "Building ASP.NET Web API OData Services" by Brian Noyes. The module, "Consuming OData Services...", demonstrates consuming a Web API OData service with Breeze.

Please review Brian's brilliant blog post with step-by-step instructions for building a Breeze/Web API OData sample which includes a downloadable sample.

Be sure to specify an absolute path for your service address (AKA serviceName), e.g, "http://localhost:1234/odata" instead of just "/odata". Relative paths work for queries but apparently not for saveChanges.

Brian highlights a critical OData configuration step that is so important, it bears repeating here.

Open the App_Start folder in the project, open WebApiConfig.cs. Add a helper method to define an Entity Data Model:

public static IEdmModel GetEdmModel()
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     builder.Namespace = "WebAPIODataWithBreezeConsumer.Models";  // DON'T FORGET THIS!
     return builder.GetEdmModel();

The ODataConventionModelBuilder just needs to know the collections you want to expose. It will reflect on the types, and declare all their properties in the EDM with corresponding EDM types, will follow navigation properties to related entities and declare those, and will infer what the entity keys are.

IMPORTANT: Note line 5 – you need to make sure the namespace of the EDM matches the namespace your entity types are contained in.


The straight Web API alternative

Breeze can go beyond what OData supports today when configured for the ASP.NET Web API and Breeze Web API controllers.

    dataService: "webApi", ...

A Breeze client is configured for Web API by default so you don't have to write this configuration in your code unless you feel it is best to be explicit.

The Breeze client can issue queries with a superset of the OData Query API.  This superset includes additional operators and supports capabilities that OData does not have such as navigation projections. A client query no longer requires the $expand syntax to reference a navigation property. And you can save a mix of entities and insert/update/delete operations in a single saveChanges call. We have more extensions in mind. 

You can stick to the standard with the ODdata configuration or leverage Breeze extensions with the Web API configuration. Choose the path that’s right for you.

We’ll  be adding more dataService adapters for other scenarios. Stay tuned.