Showing posts with label oData. Show all posts
Showing posts with label oData. Show all posts

Thursday, June 4, 2020

.Net Core 3.1 with oData code only

for notes with explanation.

Startup.cs

using System;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Builder;
using OdataDemo.Models;
using Microsoft.OData.Edm;

namespace OdataDemo
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

.Net Core 3.1 with oData

I have been cracking my head trying to solve following mysteries.
"@odata.count" is not show in the return result even after using $count=true.

odata is returning a list of object instead of in the odata format:

this:
 [
{"id":"e313596c-8fe9-4db6-b7cb-84f2e059447b","name":"Cody Allen","score":130},{"id":"349a4642-82bd-440f-a05b-ed27ed60cade","name":"Viral Pandya","score":140},{"id":"44fe2696-5285-470f-8b4c-ad983e5241b4","name":"student3","score":120},
{"id":"f2e9d6b7-6825-435b-a86a-37ac89ef77cb","name":"student4","score":150},
{"id":"3a4982f3-a9f3-4bc7-8886-315e7082fd59","name":"student5","score":100}
]

instead of this:
{
"@odata.context":"https://localhost:44372/odata/$metadata#Students",
"@odata.count":5,
"value":[
{"Id":"445bb0cf-efe8-4420-af43-75b37d81dc13","Name":"Cody Allen","Score":130},{"Id":"ec9acefd-1b38-4a0e-aba0-de9949f6690f","Name":"Viral Pandya","Score":140},{"Id":"675ba6a5-c799-4df6-a820-15cb274c33a1","Name":"student3","Score":120},
{"Id":"6fec0f6c-60b6-4624-ad11-38443e0e077f","Name":"student4","Score":150},
{"Id":"a6eeeeb1-8d55-4418-9ab8-4df448a6e1f0","Name":"student5","Score":100}
]}