Microsoft.AspNetCore.OData
9.1.2
Prefix Reserved
See the version list below for details.
dotnet add package Microsoft.AspNetCore.OData --version 9.1.2
NuGet\Install-Package Microsoft.AspNetCore.OData -Version 9.1.2
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.1.2" />
paket add Microsoft.AspNetCore.OData --version 9.1.2
#r "nuget: Microsoft.AspNetCore.OData, 9.1.2"
// Install Microsoft.AspNetCore.OData as a Cake Addin #addin nuget:?package=Microsoft.AspNetCore.OData&version=9.1.2 // Install Microsoft.AspNetCore.OData as a Cake Tool #tool nuget:?package=Microsoft.AspNetCore.OData&version=9.1.2
ASP.NET Core OData
Component | Build | Status |
---|---|---|
ASP.NET Core OData | Rolling | |
ASP.NET Core OData | Nightly | |
.NET Foundation | Release |
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:
- ASP.NET Core OData Overview
- Getting Started
- Fundamentals Overview
- Tutorials
- OData Dev Blogs
- OData.org
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 pageAppend
~/$openapi
to each route gives a raw openapi OData page, for example,~/v1/$openapi
Please go to sample folder see more samples.
Solution:
-
- Includes Microsoft.AspNetCore.OData project, Unit Test, E2E Test & Samples
AspNetCoreOData.NewtonsoftJson.sln
- Includes Microsoft.AspNetCore.OData.NewtonsoftJson project, Unit Test, E2E Test & Samples
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:
https://www.myget.org/F/webapinetcore/api/v3/index.json (Your NuGet V3 feed URL (Visual Studio 2015+)
https://www.myget.org/F/webapinetcore/api/v2 Your NuGet V2 feed URL (Visual Studio 2012+)
4. Documentation
ODataRoutingSample: ASP.NET Core OData sample project in this repo.
ASP.NET OData 8.0 Preview for .NET 5: A blog introducing the project.
Our docs folder: Our current 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
- Issues: Report issues on Github issues.
- Questions: Ask questions on Stack Overflow.
- Feedback: Please send mails to odatafeedback@microsoft.com.
- Team blog: Please visit https://devblogs.microsoft.com/odata/ and http://www.odata.org/blog/.
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 | Versions 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. |
-
net8.0
- Microsoft.OData.Core (>= 8.2.2 && < 9.0.0)
- Microsoft.OData.Edm (>= 8.2.2 && < 9.0.0)
- Microsoft.OData.ModelBuilder (>= 2.0.0 && < 3.0.0)
- Microsoft.Spatial (>= 8.2.2 && < 9.0.0)
NuGet packages (193)
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 5 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
|
|
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.
|
|
linq2db/linq2db
Linq to database provider.
|
Version | Downloads | Last updated | |
---|---|---|---|
9.1.3 | 0 | 1/15/2025 | |
9.1.1 | 138,946 | 11/19/2024 | |
9.1.0 | 39,394 | 11/13/2024 | |
9.0.0 | 822,233 | 8/20/2024 | |
9.0.0-rc.1 | 2,749 | 7/15/2024 | |
9.0.0-preview.2 | 1,604 | 6/5/2024 | |
8.2.7 | 71,340 | 11/19/2024 | |
8.2.5 | 2,978,999 | 3/1/2024 | |
8.2.4 | 1,933,873 | 1/17/2024 | |
8.2.3 | 2,020,097 | 9/6/2023 | |
8.2.0 | 2,115,724 | 5/18/2023 | |
8.1.2 | 574,454 | 5/2/2023 | |
8.1.1 | 441,955 | 4/4/2023 | |
8.1.0 | 243,149 | 3/27/2023 | |
8.0.12 | 2,867,547 | 12/9/2022 | |
8.0.11 | 1,976,469 | 8/16/2022 | |
8.0.10 | 1,977,502 | 4/27/2022 | |
8.0.9 | 162,103 | 4/14/2022 | |
8.0.8 | 942,379 | 2/19/2022 | |
8.0.7 | 281,688 | 2/1/2022 | |
8.0.6 | 968,569 | 1/11/2022 | |
8.0.5 | 17,874 | 1/7/2022 | |
8.0.4 | 1,172,810 | 11/9/2021 | |
8.0.3 | 369,223 | 10/1/2021 | |
8.0.2 | 604,344 | 9/1/2021 | |
8.0.1 | 396,207 | 7/7/2021 | |
8.0.0 | 85,759 | 7/3/2021 | |
8.0.0-rc3 | 24,254 | 6/7/2021 | |
8.0.0-rc2 | 48,739 | 5/1/2021 | |
8.0.0-rc | 58,498 | 3/30/2021 | |
8.0.0-preview3 | 41,314 | 12/17/2020 | |
8.0.0-preview2 | 5,356 | 11/4/2020 | |
8.0.0-preview | 4,667 | 9/29/2020 | |
8.0.0-beta | 7,643 | 1/26/2021 | |
7.7.7 | 5,179 | 11/11/2024 | |
7.7.6 | 24,672 | 7/12/2024 | |
7.7.5 | 23,029 | 5/7/2024 | |
7.7.4 | 120,490 | 1/29/2024 | |
7.7.3 | 48,020 | 11/30/2023 | |
7.7.2 | 98,837 | 10/29/2023 | |
7.7.1 | 60,596 | 7/25/2023 | |
7.7.0 | 285,398 | 5/25/2023 | |
7.6.5 | 51,094 | 3/16/2023 | |
7.6.4 | 62,210 | 2/16/2023 | |
7.6.3 | 107,563 | 12/28/2022 | |
7.6.1 | 150,953 | 10/24/2022 | |
7.6.1-beta | 2,006 | 1/24/2022 | |
7.6.0 | 16,756 | 10/20/2022 | |
7.6.0-beta | 1,093 | 10/31/2021 | |
7.5.18 | 77,898 | 10/21/2022 | |
7.5.17 | 349,437 | 8/19/2022 | |
7.5.15 | 227,729 | 6/4/2022 | |
7.5.14 | 1,163,199 | 3/9/2022 | |
7.5.13 | 18,414 | 2/25/2022 | |
7.5.12 | 1,075,342 | 10/8/2021 | |
7.5.11 | 91,093 | 10/1/2021 | |
7.5.10 | 201,969 | 8/26/2021 | |
7.5.9 | 34,182 | 8/13/2021 | |
7.5.8 | 1,010,792 | 5/1/2021 | |
7.5.7 | 461,756 | 3/26/2021 | |
7.5.6 | 1,452,585 | 2/17/2021 | |
7.5.5 | 403,467 | 1/20/2021 | |
7.5.4 | 150,762 | 12/24/2020 | |
7.5.2 | 756,824 | 11/12/2020 | |
7.5.1 | 552,379 | 10/22/2020 | |
7.5.0 | 654,093 | 9/18/2020 | |
7.4.1 | 2,177,053 | 5/22/2020 | |
7.4.0 | 480,882 | 4/20/2020 | |
7.4.0-beta2 | 93,426 | 4/10/2020 | |
7.4.0-beta | 120,238 | 3/4/2020 | |
7.3.0 | 2,050,897 | 12/23/2019 | |
7.3.0-beta | 22,943 | 12/12/2019 | |
7.2.3 | 162,139 | 12/11/2019 | |
7.2.2 | 336,270 | 10/9/2019 | |
7.2.1 | 989,952 | 8/5/2019 | |
7.1.0 | 1,849,006 | 11/20/2018 | |
7.0.1 | 749,025 | 7/18/2018 | |
7.0.0 | 183,571 | 6/29/2018 | |
7.0.0-beta4 | 13,894 | 5/31/2018 |