Skip to content
This repository has been archived by the owner. It is now read-only.
OData parser for NHibernate.
C# Other
  1. C# 99.4%
  2. Other 0.6%
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.



LGPL License.

Download from NuGet.


NHibernate.OData is an OData parser for NHibernate.

The goal of NHibernate.OData is to parse OData query strings and turn them into ICriteria. It currently implements the $filter, $orderby, $skip and $top sections of the OData specification located at

The availability of stand-alone parsers like these is very limited. At the time this project was started, the only good parser available was part of the WCF Web API project This project contains a complete OData parser which applies the filters of an OData query string to an IQueryable. This code can be found in the WCFWebApi/src/Microsoft.ApplicationServer.Http/Microsoft/ApplicationServer/Query directory at However, the license of this source code limits its usage in production environments. This project was created as an open source alternative.


There are two ways in which NHibernate.OData can be used. If all that is required is a way to query the database, the ODataQuery extension method can be used. This method parses an OData query string and creates an ICriteria for that query string on a specific entity:

ICriteria query = session.ODataQuery<Customer>("$filter=substringof('Harry', Name)");

NHibernate.OData requires some caching based on the session factory associated with the current session. When using the extension methods on ODataParser, a static shared instance is used to manage this cache. If it is necessary to manage the lifetime of this cache, the ODataContext class can be used instead. Internally the static extension methods on the ODataParser class route calls to the shared ODataContext instance.

Alternatively, the ODataService class provides a service for implementing a full OData service. To use the ODataService class, a new instance of this class must be instantiated for an ISessionFactory and a few configuration parameters (see the constructor documentation). Queries can then be executed using the Query method on the ODataService class which takes a session, OData path and OData query string.

The demo application which is included in the ZIP file shows how such a service can be implemented with minimal effort. This demo application makes use of NHttp so it can run without a web server available.

Join type

The default join type of NHibernate.OData is the inner join type. This may not give the expected results. If you want the join type to be the left outer join type, call the overload that takes a configuration object and set the OuterJoin property to true.


The current implementation does not access metadata while querying. This results in the following limitations:

  • The cast operator is a no-op except for when casting to integer types. In that case it is converted to a round call;

  • The isof operator is a no-op.

Also, currently NHibernate.OData is read-only and can only be used to query the database.


Bugs should be reported through github at


NHibernate.OData is licensed under the LGPL 3.

You can’t perform that action at this time.