Extenso.AspNetCore.OData 9.4.0

dotnet add package Extenso.AspNetCore.OData --version 9.4.0
                    
NuGet\Install-Package Extenso.AspNetCore.OData -Version 9.4.0
                    
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="Extenso.AspNetCore.OData" Version="9.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Extenso.AspNetCore.OData" Version="9.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Extenso.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 Extenso.AspNetCore.OData --version 9.4.0
                    
#r "nuget: Extenso.AspNetCore.OData, 9.4.0"
                    
#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=Extenso.AspNetCore.OData&version=9.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Extenso.AspNetCore.OData&version=9.4.0
                    
Install as a Cake Tool

NuGet NuGet

<img src="https://github.com/gordon-matt/Extenso/blob/master/_Misc/ExtensoLogo.png" alt="Logo" width="250" />

Extenso.AspNetCore.OData

Intro

This package contains a GenericODataController, as well as a GenericMappedODataController if working from DAOs instead of entities is required. To get started, see the Demo project in this repo, which has a fully working CRUD demo using OData, KendoGrid and KnockoutJS.

Getting Started

This package is dependant on the "Extenso.Data.Entity" package, which provides the IRepository<T> and IMappedRepository<T, TModel> interfaces required. Follow the instructions in the Extenso.Data.Entity package to get your IDbContextFactory and repositories registered for dependency injection. Once that is done, you can use the GenericODataController or GenericMappedODataController in your ASP.NET Core application as follows:

Setup an IODataRegistrar to register your OData controllers and models:

public class ODataRegistrar : IODataRegistrar
{
    public void Register(ODataOptions options)
    {
        ODataModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<Person>("PersonApi");
        options.AddRouteComponents("odata", builder.GetEdmModel());
    }
}

NOTE: Using an IODataRegistrar is not required, but it is a good way to keep your OData configuration clean and organized. Moreover, it's helpful if you have multiple projects each with their own OData controllers that need to be registered.

services.AddSingleton<IODataRegistrar, ODataRegistrar>();

services.AddOData((options, serviceProvider) =>
{
    options.Select().Expand().Filter().OrderBy().SetMaxTop(null).Count();

    // You may have many IODataRegistrar implementations in Razor Class Libraries or other projects.
    var registrars = serviceProvider.GetRequiredService<IEnumerable<IODataRegistrar>>();
    foreach (var registrar in registrars)
    {
        registrar.Register(options);
    }
});

And now all you need to do is create your OData controllers. Example:

public class PersonApiController : BaseODataController<Person, int>
{
    public PersonApiController(IAuthorizationService authorizationService, IRepository<Person> repository)
        : base(authorizationService, repository)
    {
    }

    protected override int GetId(Person entity) => entity.Id;

    protected override void SetNewId(Person entity)
    {
        // Don't try to set the ID here unless it's not auto incremented, such as a GUID, for example.
    }
}

As simple as that.. you now have a fully functional OData API for your Person entity. If you have a grid that supports OData out of the box, such as KendoGrid, you can now bind it to this API very easily:

self.apiUrl = "/odata/PersonApi";

$("#grid").kendoGrid({
    data: null,
    dataSource: {
        type: 'odata-v4',
        transport: {
            read: self.apiUrl
        },
        // etc..

Take a look at the demo projects for more details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Extenso.AspNetCore.OData:

Package Downloads
MantleFramework.Web

Mantle - Web. Includes admin pages for Membership, Localization, Configuration, Tenants, Scheduled Tasks, etc. Also includes many extensions and helper classes.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.4.0 132 6/16/2025
9.3.1 148 6/2/2025
9.3.0 106 5/25/2025
9.2.0 87 5/3/2025
9.1.0 197 3/23/2025
9.0.0 156 1/4/2025
8.0.0 144 5/15/2024
7.0.2 231 8/19/2023
7.0.1 227 6/12/2023
7.0.0 374 11/27/2022
6.1.0 363 11/18/2022
6.0.3 1,912 5/21/2022
6.0.2 607 4/1/2022
6.0.1 648 2/21/2022
6.0.0 569 1/14/2022
5.0.0 638 12/7/2020
3.1.0 704 6/15/2020
2.0.0 704 2/24/2020
1.2.0 859 2/27/2019
1.1.3 911 10/26/2018
1.1.2 1,272 6/30/2018
1.1.0 1,215 6/20/2018
1.0.1 1,352 5/17/2018
1.0.0 1,089 5/16/2018