Community.OData.Linq.Json 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Community.OData.Linq.Json --version 2.0.0                
NuGet\Install-Package Community.OData.Linq.Json -Version 2.0.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="Community.OData.Linq.Json" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Community.OData.Linq.Json --version 2.0.0                
#r "nuget: Community.OData.Linq.Json, 2.0.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 Community.OData.Linq.Json as a Cake Addin
#addin nuget:?package=Community.OData.Linq.Json&version=2.0.0

// Install Community.OData.Linq.Json as a Cake Tool
#tool nuget:?package=Community.OData.Linq.Json&version=2.0.0                

Community.OData.Linq

Use OData filter text query in linq expresson for any IQuerable. Support web and desktop applications.

Sample

Please check samples below to get started:

.NET Fiddle

https://dotnetfiddle.net/7Ndwot

Console app

    using System;
    using System.Linq;

    using Community.OData.Linq;

    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

https://github.com/IharYakimush/comminity-data-odata-linq/wiki

Supported OData parameters

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

Nuget

Contribution

Please feel free to create issues and pool requests to develop branch

Build Status

Build status

References

Majority of the code was taken from https://github.com/OData/WebApi

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 Community.OData.Linq.Json:

Package Downloads
Aguacongas.IdentityServer.Admin

Expose OData controllers to manage TheIdServer.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Community.OData.Linq.Json:

Repository Stars
Aguafrommars/TheIdServer
OpenID/Connect, OAuth2, WS-Federation and SAML 2.0 server based on Duende IdentityServer and ITFoxtec Identity SAML 2.0 with its admin UI
Version Downloads Last updated
2.1.24-rc 860 6/5/2022
2.1.0 33,178 1/3/2022
2.0.0 525 12/22/2021
1.4.3 11,965 5/26/2021
1.4.2 22,654 11/18/2018
1.4.1 817 8/23/2018
1.4.0 2,033 4/12/2018
1.2.0 1,270 3/17/2018
1.1.0 950 2/28/2018

Significant improvement in query initialization performance. Support ToArrayAsync(), ToListAsync(), and all other provider specific methods. More integration tests for Entity Framework and CosmosDb SQL API. Breaking Changes: net4.5 not suported anymore. Obsolete methods removed (.SelectExpandJsonToken() and .SelectExpandJson())