Dharv
Dharv

Reputation: 51

Getting Breeze OData results in Container and Next0 object in .Net 5 web api

I was trying .net5 with breeze from this git repo https://github.com/Breeze/northwind-demo/tree/master/server/NorthwindNet5. Its works as expected and I am getting result as below enter image description here

But when I add OData to breeze configuration and apply filter with select (http://localhost:4000/api/breeze/customers?select=Name) I am getting result in nested container. enter image description here

This is because of AddNewtonsoftJson in ConfigureServices

 services.AddControllers().AddNewtonsoftJson(opt =>
        {
            //Set Breeze defaults for entity serialization
            var ss = JsonSerializationFns.UpdateWithDefaults(opt.SerializerSettings);
            if (ss.ContractResolver is DefaultContractResolver resolver)
            {
                resolver.NamingStrategy = null;  // remove json camelCasing; names are converted on the client.
            }
            ss.Formatting = Newtonsoft.Json.Formatting.Indented; // format JSON for debugging
        });

Can anyone please suggest if there is any configuration changes need to made to get direct result after applying filters

Upvotes: 2

Views: 89

Answers (1)

Dharv
Dharv

Reputation: 51

Issue is fixed by adding package ODataNewtwonsoftJson, after adding this in configurationservices I am not getting additional OData information in response

Modified below code in startup.cs

using Microsoft.AspNetCore.OData.NewtonsoftJson;

services.AddControllers().AddODataNewtonsoftJson().AddNewtonsoftJson(opt =>
        {

           // Set Breeze defaults for entity serialization
            var ss = JsonSerializationFns.UpdateWithDefaults(opt.SerializerSettings);
            if (ss.ContractResolver is DefaultContractResolver resolver)
            {
                resolver.NamingStrategy = null;  // remove json camelCasing; names are converted on the client.
            }
            ss.Formatting = Newtonsoft.Json.Formatting.Indented; // format JSON for debugging

            //var ss = opt.SerializerSettings;
            //ss.Formatting = Newtonsoft.Json.Formatting.Indented;
        });

Upvotes: 1

Related Questions