DotNetExtras.OData 1.0.1

dotnet add package DotNetExtras.OData --version 1.0.1
                    
NuGet\Install-Package DotNetExtras.OData -Version 1.0.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="DotNetExtras.OData" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetExtras.OData" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="DotNetExtras.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 DotNetExtras.OData --version 1.0.1
                    
#r "nuget: DotNetExtras.OData, 1.0.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.
#:package DotNetExtras.OData@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetExtras.OData&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=DotNetExtras.OData&version=1.0.1
                    
Install as a Cake Tool

DotNetExtras.OData

DotNetExtras.OData is a .NET Core library handles OData filter expressions.

Use the DotNetExtras.OData library to:

  • Parse the OData filter expressions tree.
  • Validate a given filter against the custom rules.

By default, the library can check if a filter expression uses valid OData syntax (based on the Microsoft's implementation) for the given data type. In particular, it validates that the filter expression uses:

  • Supported operators (e.g., eq, ne, and, or, etc.).
  • Supported properties (e.g., name/givenName, type, etc.).

To extend the default validation capabilities, use custom rules to specify:

  • Allowed operators in the filter expression and the minimum and maximum number each operator can be used.
  • Allowed properties in the filter expression and the minimum and maximum number of times each property can be used.
  • Allowed operators that can be used with each property and the minimum and maximum number of times each operator can be used with each property.

Disclaimer

The DotNetExtras.OData library's OData specification coverage is limited to the cases covered in the demos and unit tests. While they can handle the most common scenarios, there may be features or edge cases that are not fully implemented. If you run into such issue or edge case, please open an issue.

Usage

The following example demonstrates how to parse and validate an OData filter expression:

using DotNetExtras.OData;
...
string rules;

// OData filter validator object.
ODataFilterValidator<User> validator;

// We will use this filter expression to illustrate the validation rules.
// The filter is based on the User class provided in the sample project.
string filter = "type eq 'Employee' and startsWith(name/givenName, 'john') and name/givenName ne 'Johnson'";

// This validation rule defines them as a JSON string that will be converted to the rules object.
// The rule allows the 'eq', 'and', 'ne', and 'startsWith' operators and 
// the 'type' and 'name/givenName' properties.
rules = @"{""Operators"":{""eq"":null,""and"":null,""ne"":null,""startsWith"":null}," +
        @"""Properties"":{""type"":null,""name/givenName"":null}}";

// The constructor will perform the validation of the rules.
validator = new(filter, rules);

// Check if the validation passed
if (validator.Passed)
...

// The same rule as above, only using the abbreviated notation.
rules = "eq|and|ne|startsWith|type|name/givenName";
validator = new(filter, rules);

// The following rule will make the filter expression to fail validation.
// The rule only allows the 'eq' operation for the 'type' property
// and the 'ne', 'startsWith', and 'and' operations for the 'name/givenName' property.
// The expression fails because the 'and' operator applies to the 'type' property,
// but it is not explicitly allowed (logical 'and' and 'or' operators must
// apply to both left and right operands)
rules = "type[eq]|name/givenName[ne,startsWith,and]";
validator = new(filter, rules);

// Check if the results and print validation errors.
if (!validator.Failed)
{
    foreach (string error in validator.Errors)
    {
        Console.WriteLine($"Error: {error}");
    }
}

You can find more examples in the unity tests and demos. The detailed explanation of the rules syntax is available in the documentation.

Documentation

For the complete documentation, usage details, and code samples, see:

Package

Install the latest version of the DotNetExtras.OData NuGet package from:

See also

Check out other DotNetExtras libraries at:

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.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 117 8/20/2025
1.0.0 126 8/11/2025