AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

OData metadata became invalid after using this extension. #55

Closed matteo-mosca closed 4 years ago

matteo-mosca commented 4 years ago

Hi there, I'm developing an OData service. At first I was using straight database models, and everything was working fine. Then my client asked me to add projections to custom model and that's how I found your project. I followed all your recommendations and instructions on how to use it, avoid to use EnableQuery, etc. and it "kinda" works.

If I query the OData endpoints with a REST client like Postman everrything works. But as soon as I try to give the OData feed to any OData enabled client like Power BI or the LinqPad driver I start getting different errors on the $metadata path.

The first problem I encountered was that the clients did not see the metadata document anymore. 404. I tried with postman and this did not work:

https://localhost/odata/$metadata

But this worked:

https://localhost/odata

So even if it's not clear to me why this happens after adding your extensions, I went around it with a simple rewrite. Now the clients find the document but they report it as an invalid document. This is Power BI error:

Details: "OData: The feed's metadata document appears to be invalid. Error: A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'application/xml' matches the content type 'application/json; odata.metadata=minimal; odata.streaming=true'."

And this is the error I get from the LinqPad driver:

Error: XmlException - Data at the root level is invalid. Line 1, position 1.

I hope you can help with this, I'm currently stumped.

Thanks.

BlaiseD commented 4 years ago

Maybe look at the sample WebAPI projects in the solution and go from there? (you'll have to open the solution's Configuration Manager and check the build checkboxes - they are turned off to simplify the CI build)

Both of the following work. http://localhost:16324/$metadata http://localhost:19583/$metadata

Consider inspecting the results with some client component to help figure out the difference - like with our web tests.

Seems unrelated to the extension.

matteo-mosca commented 4 years ago

I will check this out and update the issue, thank you for the feedback.

BlaiseD commented 4 years ago

Sounds good.

matteo-mosca commented 3 years ago

I tried your WebApi.OData.EFCore project, setting the connectionstring to a new local database on my sqlexpress to be sure everything was in place, and set it as startup project.

Hitting F5 gives this in the browser:

image

Database is still pristine, tables are not created so I guess it doesn't even reach the point where it initializes the dbcontext.

Then trying to connect through Power BI I get this:

image

I am pointing at the HEAD on the master branch and the only thing I changed is the connectionstring. Do you have any idea about what's going on?

Thanks.

BlaiseD commented 3 years ago

I've added two EXEs to help setup the sample web projects.

  1. Update the connection strings here and here.
  2. Run MigrationTool.
  3. Run SeedDatabase.

Your issue seems unrelated though. I would setup break points to figure out why it's blowing up for you.

This forum is really for problems/bugs related to the libraries - see some of the other closed issues.