Microsoft.AspNetCore.OData 9.2.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Microsoft.AspNetCore.OData --version 9.2.1
                    
NuGet\Install-Package Microsoft.AspNetCore.OData -Version 9.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.AspNetCore.OData" Version="9.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.AspNetCore.OData" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Microsoft.AspNetCore.OData --version 9.2.1
                    
#r "nuget: Microsoft.AspNetCore.OData, 9.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Microsoft.AspNetCore.OData&version=9.2.1
                    
Install Microsoft.AspNetCore.OData as a Cake Addin
#tool nuget:?package=Microsoft.AspNetCore.OData&version=9.2.1
                    
Install Microsoft.AspNetCore.OData as a Cake Tool

ASP.NET Core OData


Component Build Status
ASP.NET Core OData Rolling Build Status
ASP.NET Core OData Nightly Build Status
.NET Foundation Release Build status

1. Basic Usage

Microsoft.AspNetCore.OData Package Installation

Using .NET CLI:

dotnet add package Microsoft.AspNetCore.OData

Using Package Manager:

Install-Package Microsoft.AspNetCore.OData

Getting Started

Creating an OData Service

Here's a simple example of how to create an OData service using Microsoft.AspNetCore.OData:

I. Create an ASP.NET Core Application:

  • Open Visual Studio and create a new ASP.NET Core Web API project.

II. Add the Microsoft.AspNetCore.OData Package:

  • Install the package using the instructions above.

III. Define Your Models:

  • Create your data models. For example:
      namespace MyODataApp.Models
      {
          public class Product
          {
              public int Id { get; set; }
              public string Name { get; set; }
              public decimal Price { get; set; }
          }
      }
    

IV. Add an OData Controller:

  • Create a controller to handle OData requests:
      using Microsoft.AspNetCore.Mvc;
      using Microsoft.AspNetCore.OData.Routing.Controllers;
      using MyODataApp.Models;
      using System.Collections.Generic;
      using System.Linq;
    
      namespace MyODataApp.Controllers
      {
          public class ProductsController : ODataController
          {
              private static List<Product> products = new List<Product>
              {
                  new Product { Id = 1, Name = "Product 1", Price = 10.0M },
                  new Product { Id = 2, Name = "Product 2", Price = 20.0M }
              };
    
              [EnableQuery]
              public IActionResult Get()
              {
                  return Ok(products);
              }
    
              [EnableQuery]
              public IActionResult Get(int key)
              {
                  var product = products.FirstOrDefault(p => p.Id == key);
                  if (product == null)
                  {
                      return NotFound();
                  }
                  return Ok(product);
              }
          }
      }
    

V. Configure OData in Startup.cs:

  • Configure OData routes and services:

  • If you work with Program.cs, update as below. Refer to the Getting Started Guide.

      // using statements
      var builder = WebApplication.CreateBuilder(args);
    
      var modelBuilder = new ODataConventionModelBuilder();
      modelBuilder.EntityType<Order>();
      modelBuilder.EntitySet<Customer>("Customers");
    
      builder.Services.AddControllers().AddOData(
          options => options.Select().Filter().OrderBy().Expand().Count().SetMaxTop(null).AddRouteComponents(
              "odata",
              GetEdmModel()));
    
      var app = builder.Build();
    
      // Send "~/$odata" to debug routing if enable the following middleware
      // app.UseODataRouteDebug();
      app.UseRouting();
    
      app.MapControllers();
    
      app.Run();
    
      static IEdmModel GetEdmModel()
      {
          var builder = new ODataConventionModelBuilder();
          builder.EntitySet<Product>("Products");
          return builder.GetEdmModel();
      }
    
      using Microsoft.AspNetCore.Builder;
      using Microsoft.AspNetCore.Hosting;
      using Microsoft.Extensions.DependencyInjection;
      using Microsoft.OData.Edm;
      using Microsoft.OData.ModelBuilder;
    
      namespace MyODataApp
      {
          public class Startup
          {
              public void ConfigureServices(IServiceCollection services)
              {
                  services.AddControllers();
                  services.AddOData(opt => opt.AddModel("odata", GetEdmModel()).Filter().Select().Expand().OrderBy().Count().SetMaxTop(100));
              }
    
              public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
              {
                  // Send "~/$odata" to debug routing if enable the following middleware
                  // app.UseODataRouteDebug();
                  app.UseRouting();
                  app.UseEndpoints(endpoints =>
                  {
                      endpoints.MapControllers();
                      endpoints.Select().Expand().Filter().OrderBy().Count().MaxTop(100);
                      endpoints.MapODataRoute("odata", "odata", GetEdmModel());
                  });
              }
    
              private static IEdmModel GetEdmModel()
              {
                  var builder = new ODataConventionModelBuilder();
                  builder.EntitySet<Product>("Products");
                  return builder.GetEdmModel();
              }
          }
      }
    

VI. Run Your Application:

  • Start your application and navigate to /odata/Products to see your OData service in action.

That's it.

2. Github Repository

This is the official ASP.NET Core OData repository. ASP.NET Core OData is a server side library built upon ODataLib and ASP.NET Core.

Blogs:

Documentation:

For comprehensive documentation, please refer to the following links:

Example:

  • ODataRoutingSample: ASP.NET Core OData sample project in this repo.

    • ~/$odata gives a static routing table page of the service

    • ~/swagger gives a swagger/openapi page

    • Append ~/$openapi to each route gives a raw openapi OData page, for example, ~/v1/$openapi

    Please go to sample folder see more samples.

Solution:

3. Building, Testing, Debugging and Release

3.1 Building and Testing in Visual Studio

Visual Studio 2022 is required to build the source project in order to support the DateOnly and TimeOnly types, which were introduced in .NET 6.

3.2 One-click build and test script in command line

Coming soon.

3.3 Debug

The symbol package is uploaded to nuget symbol server.

It supports source link debug. Remember to check Enable Source Link support if you debug using Visual Studio.

3.4 Nightly Builds

The nightly build process will upload NuGet packages for ASP.NET Core OData to:

To connect to webapinightly feed, use this feed URL:

4. Documentation

5. Community

5.1 Contribution

Any contributions, feature requests, bugs and issues are welcome.

5.2 Reporting Security Issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter. You can also find these instructions in this repo's SECURITY.md.

5.3 Support

Code of Conduct

This project has adopted the .NET Foundation Contributor Covenant Code of Conduct. For more information see the Code of Conduct FAQ.

.NET Foundation

This project is supported by the .NET Foundation.

AspNetCoreOData is a Copyright of © .NET Foundation and other contributors. It is licensed under MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (201)

Showing the top 5 NuGet packages that depend on Microsoft.AspNetCore.OData:

Package Downloads
Microsoft.AspNetCore.OData.Versioning

A service API versioning library for Microsoft ASP.NET Core and OData v4.0.

AutoMapper.AspNetCore.OData.EFCore

Creates LINQ expressions from ODataQueryOptions and executes the query.

Microsoft.AspNetCore.OData.NewtonsoftJson

This package contains customized Newtonsoft.Json serializer converters to support OData serialization.

FenixAlliance.ACL.Dependencies

Application Component for the Alliance Business Suite.

Asp.Versioning.OData

A service API versioning library for Microsoft ASP.NET Core with OData v4.0.

GitHub repositories (35)

Showing the top 20 popular GitHub repositories that depend on Microsoft.AspNetCore.OData:

Repository Stars
dotnet/efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
aspnetboilerplate/aspnetboilerplate
ASP.NET Boilerplate - Web Application Framework
MapsterMapper/Mapster
A fast, fun and stimulating object to object Mapper
radzenhq/radzen-blazor
Radzen Blazor is a set of 90+ free native Blazor UI components packed with DataGrid, Scheduler, Charts and robust theming including Material design and FluentUI.
dotnet/aspnet-api-versioning
Provides a set of libraries which add service API versioning to ASP.NET Web API, OData with ASP.NET Web API, and ASP.NET Core.
JasperFx/marten
.NET Transactional Document DB and Event Store on PostgreSQL
linq2db/linq2db
Linq to database provider.
nhibernate/nhibernate-core
NHibernate Object Relational Mapper
grandnode/grandnode
Open source, headless, multi-tenant eCommerce platform built with .NET Core, MongoDB, AWS DocumentDB, Azure CosmosDB, Vue.js.
smartstore/Smartstore
A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 7
bitfoundation/bitplatform
Build all of your apps using what you already know and love ❤️
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
markjprice/cs10dotnet6
Repository for the Packt Publishing book titled "C# 10 and .NET 6 - Modern Cross-Platform Development" by Mark J. Price
gustavnavar/Grid.Blazor
Grid component with CRUD for Blazor (client-side and server-side) and ASP.NET Core MVC
OData/odata.net
ODataLib: Open Data Protocol - .NET Libraries and Frameworks
dotnet/dotnet
Home of .NET's Virtual Monolithic Repository which includes all the code needed to build the .NET SDK.
ProfessionalCSharp/ProfessionalCSharp7
Code samples for the book Professional C# 7 and .NET Core 2.0 (with updates for 2.1), Wrox Press
DataDog/dd-trace-dotnet
.NET Client Library for Datadog APM
OData/RESTier
A turn-key library for building RESTful services
ShawnShiSS/clean-architecture-azure-cosmos-db
A starting point to build a web API to work with Azure Cosmos DB using .NET 5 and Azure Cosmos DB .NET SDK V3, based on Clean Architecture and repository design pattern. Partition key is also implemented through the repository pattern.
Version Downloads Last updated
9.3.0 10,919 10 days ago
9.2.1 99,871 a month ago
9.2.0 195,827 3 months ago
9.1.3 117,129 3 months ago
9.1.1 521,862 5 months ago
9.1.0 96,573 5 months ago
9.0.0 1,482,601 8 months ago
9.0.0-rc.1 3,410 9 months ago
9.0.0-preview.2 1,706 6/5/2024
8.3.0 2,194 10 days ago
8.2.7 333,985 5 months ago
8.2.5 3,883,123 3/1/2024
8.2.4 2,392,081 1/17/2024
8.2.3 2,350,651 9/6/2023
8.2.0 2,362,272 5/18/2023
8.1.2 701,238 5/2/2023
8.1.1 468,020 4/4/2023 8.1.1 is deprecated.
8.1.0 249,391 3/27/2023 8.1.0 is deprecated.
8.0.12 3,116,790 12/9/2022
8.0.11 2,074,030 8/16/2022
8.0.10 2,069,698 4/27/2022
8.0.9 168,006 4/14/2022
8.0.8 989,543 2/19/2022
8.0.7 301,436 2/1/2022
8.0.6 1,093,682 1/11/2022
8.0.5 18,672 1/7/2022
8.0.4 1,200,472 11/9/2021
8.0.3 384,604 10/1/2021
8.0.2 736,541 9/1/2021
8.0.1 404,917 7/7/2021
8.0.0 102,626 7/3/2021
8.0.0-rc3 24,307 6/7/2021
8.0.0-rc2 49,262 5/1/2021
8.0.0-rc 60,987 3/30/2021
8.0.0-preview3 41,450 12/17/2020
8.0.0-preview2 5,443 11/4/2020
8.0.0-preview 4,724 9/29/2020
8.0.0-beta 7,706 1/26/2021
7.7.8 12,477 3 months ago
7.7.7 13,267 5 months ago
7.7.6 48,251 9 months ago
7.7.5 32,668 5/7/2024
7.7.4 176,894 1/29/2024
7.7.3 59,114 11/30/2023
7.7.2 148,549 10/29/2023
7.7.1 70,637 7/25/2023
7.7.0 353,976 5/25/2023
7.6.5 53,583 3/16/2023
7.6.4 66,731 2/16/2023
7.6.3 115,368 12/28/2022
7.6.1 164,928 10/24/2022
7.6.1-beta 2,035 1/24/2022
7.6.0 20,396 10/20/2022
7.6.0-beta 1,124 10/31/2021
7.5.18 90,528 10/21/2022
7.5.17 380,403 8/19/2022
7.5.15 234,195 6/4/2022
7.5.14 1,239,619 3/9/2022
7.5.13 19,745 2/25/2022
7.5.12 1,151,720 10/8/2021
7.5.11 95,478 10/1/2021
7.5.10 206,605 8/26/2021
7.5.9 37,136 8/13/2021
7.5.8 1,038,877 5/1/2021
7.5.7 472,894 3/26/2021
7.5.6 1,557,994 2/17/2021
7.5.5 409,118 1/20/2021
7.5.4 153,832 12/24/2020
7.5.2 781,551 11/12/2020
7.5.1 563,975 10/22/2020
7.5.0 666,115 9/18/2020
7.4.1 2,222,858 5/22/2020
7.4.0 486,611 4/20/2020
7.4.0-beta2 107,179 4/10/2020
7.4.0-beta 121,315 3/4/2020
7.3.0 2,094,561 12/23/2019
7.3.0-beta 23,150 12/12/2019
7.2.3 163,442 12/11/2019
7.2.2 338,292 10/9/2019
7.2.1 1,017,434 8/5/2019
7.1.0 1,863,916 11/20/2018
7.0.1 758,527 7/18/2018
7.0.0 202,976 6/29/2018
7.0.0-beta4 14,069 5/31/2018