Breeze and the EdmBuilder for OData v4
Asked Answered
H

1

9

I was able to create an OData (v3) service with WebApiOdata and EntityFramework at server side and Breeze at client side thanks to this document.

Now I'd like to do the same with the version 4 of OData spec. but there is a problem. The EdmBuilder class provided by Breeze depends on the 'Microsoft.Data.Edm' which is related to the version 3.

In the EdmBuilder these 2 lines prevent the project from building:

using Microsoft.Data.Edm.Csdl;
using Microsoft.Data.Edm.Validation;

which is normal, because my project has a reference to 'Microsoft.OData.Edm'(for v4) instead of 'Microsoft.Data.Edm'(for v3).

So I replaced the 2 using statements, by this:

using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;

Now the project can build, but at runtime it throws this exception

"Encountered the following errors when parsing the EDMX document: UnexpectedXmlElement : The element 'Edmx' was unexpected for the root element. The root element should be Edmx. : (1, 40)"

from the EdmBuilder class at this point:

using (var reader = XmlReader.Create(stream))
            {
                return EdmxReader.Parse(reader);
            }

Is there any way to solve this problem ??? like a new EdmBuilder class that I can download somewhere?

P.S.: I'm using code first migration and this code to configure OData route in the 'WebApiConfig' :

config.MapODataServiceRoute(
            routeName: "ODataRoute",
            routePrefix: "OData",
            model: EdmBuilder.GetEdm<MyDbContext>(),
            batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
Harmful answered 27/7, 2014 at 16:52 Comment(0)
B
7

We are currently working on a breeze release that works with OData v 4.0. I will post back here when it is released, which should be in the fairly near future.

Britney answered 29/7, 2014 at 17:20 Comment(10)
I would really love it if the EdmBuilder would support the adding of EntitySets the same way that ODataCoventionBuilder does rather than just taking a DbContext. I don't use EF because we are stored procedure based.Mote
In my V3 project i just did an update to the "microsoft.aspnet.webapi.odata" (for version 5.1.2) lib, I was surprised to see that the ODataConventionModelBuilder works just fine. I register my OData route like this: ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Product>("Products"); config.Routes.MapODataRoute(routeName: "odata",routePrefix: "odata",model: builder.GetEdmModel(),batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)); Now I dont get the "406 not acceptable" error! So no need for the breeze emdbuilder?!Harmful
Can some one confirm this, because it seems working just fine? Notice that there is no namespace configuration.Harmful
@Harmful I'm getting a Metadata query failed using angular.breeze with OData v4.Primalia
@FlorianF. I have the same probleme with my v4 project, its a "DataJs" issue, the maximum version allowed is v3.Harmful
@Jay Can you share any more information about the direction Breeze will take to support OData v4? How will breeze.js support it given that datajs does not? Will breeze.server.net use the new OData v4 formatter support in Web API 2.2 or continue to use JSON.NET?Foreyard
I started working on an OData v4 adapter for client-size BreezeJS that uses the olingo library that @JayTraband mentions above. Very early work-in-progress, contributions welcome! github.com/michaelbromley/breezejs-odata4-adapterPasteup
Excellent, this is great progress. How are you handling date/time fields ( as opposed to DateTimeOffsets)?Britney
Hi Jay. Any news regarding creating an EdmBuilder that can generate an OData.Edm.IEdmModel instead of a Data.Edm.IEdmModel?Aftmost
@Harmful ODataConventionModelBuilder only works in a narrow set of circumstances, i.e. where your model actually does conform to conventions.Aftmost

© 2022 - 2024 — McMap. All rights reserved.