Search code examples
asp.net-web-apiodatabreeze

BreezeJS/WebApi OData minimal metadata


I have an WebApi OData endpoint that I'm querying with BreezeJS, and I'm having an issue with the json payload. When I query the endpoint with BreezeJS, as opposed to directly querying the endpoint via url, the json payload is ~2x, and it appears to be because the response includes full metadata.

Example, querying with Breeze:

{
        "Entity": {
            "Id": 3,
            "LegacyId": 21,
            "Type": "Company",
            "odata.id": "http://localhost/odata/Entities(3)",
            "odata.type": "Test.Models.Entity"
        },
        "[email protected]": "http://localhost/odata/Answers(2)/Entity",
        "Question": {
            "Id": 1,
            "Name": "Name",
            "Type": "string",
            "odata.id": "http://localhost/odata/Questions(1)",
            "odata.type": "Test.Models.Question"
        },
        "[email protected]": "http://localhost/odata/Answers(2)/Question",
        "EntityId": 3,
        "Id": 2,
        "Modified": "2015-05-22T14:56:26.477",
        "[email protected]": "Edm.DateTime",
        "QuestionId": 1,
        "Value": "Some Company Name",
        "odata.id": "http://localhost/odata/Answers(2)",
        "odata.type": "Test.Models.Answer"
    }

Contrasted with querying http://localhost/odata/Answers(3):

{
        "Entity": {
            "Id": 3,
            "LegacyId": 21,
            "Type": "Company"
        },
        "Question": {
            "Id": 1,
            "Name": "Name",
            "Type": "string"
        },
        "EntityId": 3,
        "Id": 2,
        "Modified": "2015-05-22T14:56:26.477",
        "QuestionId": 1,
        "Value": "Some Company Name"
    }

Is there any way to return the minimal metadata through the BreezeJS query?


Solution

  • A Breeze controller exposes more metadata to allow the breeze client to do advanced things like automatic client side validation depending on server side data annotations. That's why the metadata returned by a Breeze controller needs to be much richer than the metadata returned by an OData endpoint.

    If you don't need the extra functionality on the client side, you can make your Breeze app consume a simple OData endpoint, instead of the advanced Breeze endpoint. I.e. don't implement the Breeze controller on the server side, and point your breeze EntityManager directly to the OData endpoint.

    Here are the docs for consuming an OData endpoint directly from Breeze, without a Breeze controller