OData2Linq 1.1.0

dotnet add package OData2Linq --version 1.1.0                
NuGet\Install-Package OData2Linq -Version 1.1.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="OData2Linq" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OData2Linq --version 1.1.0                
#r "nuget: OData2Linq, 1.1.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.
// Install OData2Linq as a Cake Addin
#addin nuget:?package=OData2Linq&version=1.1.0

// Install OData2Linq as a Cake Tool
#tool nuget:?package=OData2Linq&version=1.1.0                

NuGet Version

OData2Linq

Apply an OData text query (filter, order by, select, ..) to an IQueryable expression.

Features

  • Manipulate an IQueryable expression with OData text query

Supported OData parameters

Params In Memory Collections Entity Framework CosmosDB SQL API
$filter + + +
$orderby + + +
$select + + -
$expand + + -
$top + + +
$skip + + +

Samples

Please check samples below to get started

.NET Fiddle

https://dotnetfiddle.net/6dLB2g

Console app

using System;
using System.Linq;
using OData2Linq;

public class Entity
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public static class GetStartedDemo
{
    public static void Demo()
    {
        Entity[] items =
        {
            new Entity { Id = 1, Name = "n1" },
            new Entity { Id = 2, Name = "n2" },
            new Entity { Id = 3, Name = "n3" }
        };
        IQueryable<Entity> query = items.AsQueryable();

        var result = query.OData().Filter("Id eq 1 or Name eq 'n3'").OrderBy("Name desc").TopSkip("10", "0").ToArray();

        // Id: 3 Name: n3
        // Id: 1 Name: n1
        foreach (Entity entity in result)
        {
            Console.WriteLine("Id: {0} Name: {1}", entity.Id, entity.Name);
        }
    }
}

Support ToArrayAsync(), ToListAsync(), and all other provider specific methods.

Use .ToOriginalQuery() after finishing working with OData to be able to support provider specific methods of original query.

Entity Framework async data fetch.

Student[] array = await dbContext.Students.OData()
                .Filter("LastName eq 'Alexander' or FirstMidName eq 'Laura'")
                .OrderBy("EnrollmentDate desc")
                .TopSkip("1","1")
                .ToOriginalQuery() // required to be able to use .ToArrayAsync() next.
                .ToArrayAsync();

ISelectExpandWrapper[] select2 = await dbContext.Students.OData()
                .Filter("LastName eq 'Alexander' or FirstMidName eq 'Laura'")
                .OrderBy("EnrollmentDate desc")
                .SelectExpandAsQueryable("LastName", "Enrollments($select=CourseId)") //.SelectExpandAsQueryable() use .ToOriginalQuery() implicitly, so not need to call it.
                .ToArrayAsync()

CosmosDb SQL API async data fetch.

var item = await Container.GetItemLinqQueryable<TestEntity>().OData()
                .Filter($"Id eq '{id1}'")
                .TopSkip("1")
                .ToOriginalQuery() // required to be able to use .ToFeedIterator() next.
                .ToFeedIterator()
                .ReadNextAsync()

Advanced code samples at wiki

See the Wiki pages

Contribution

Please feel free to create issues and pull requests to the main branch.

Nuget

Package NuGet Info
OData2Linq NuGet Version OData v8 support
Community.OData.Linq.Json NuGet Version Still works on odata v7 libraries. Open an issue to create a new package for odata v8.
Community.OData.Linq.AspNetCore NuGet Version Still works on odata v7 libraries. Open an issue to create a new package for odata v8.

References

This project is based on the following project: https://github.com/IharYakimush/comminity-data-odata-linq

The repository is a fork from: https://github.com/OData/AspNetCoreOData

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on OData2Linq:

Package Downloads
Aguacongas.IdentityServer

TheIdServer IndentityServer4 abstraction and extensions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 131 2/17/2025
1.0.0 89 2/13/2025