Skip to content


C#/.NET 24

Converting ODataQueryOptions into LINQ Expressions in C#

OData makes it very easy for us to pass query options from the URL down to an object mapper like EntityFramework. However, this somehow happens automagically and cannot be really controlled in code. In this blog post I show how we can extract and convert FilterQueryOption and OrderByQueryOption to manually apply them to our underlying LINQ provider. Let’s start with […]

C#/.NET 1

Modifying ODataQueryOptions on the fly

ODATA provides several methods to validate the query options a client can specify. However it is not too easy to modify them, which might become necessary when we only want to allow certain options in relation to one another. In this article I will show how this can be done on a per request level or via an attribute. The […]

C#/.NET 4

More Fun with your ODATA Models and AutoMapper

In our last post Separating your ODATA Models from the Persistence Layer with AutoMapper I showed how we can separate our public API Model from the internal persistence layer. In this post I will show how we can re-model the public API model without changing the internal data model. In the example from the previous post I showed our model […]

C#/.NET 1

Simplifying OData Controllers by using generic controller classes

Writing Odata Controllers usually involves a lot of boiler-plate code (and scaffolders are of no real help here either). However, when decoupling and unifying the business logic it is possible to also generalise the associated controllers and reduce their coding to a minimum. A typical Odata controller using IEntityManager (as described in Using Dependency Injection with StructureMap to decouple business […]

C#/.NET 0

[NoBrainer] PUT/PATCH/MERGE with OData Service Client

Visual Studio supports the generation of data service clients (Service references) for OData services. A data service client is a .NET class that contains methods for accessing the OData service and gets generated based on the metadata provided by the OData service. The client acts as a proxy and translates the method calls into HTTP requests. Mike Wasson describes in […]

C#/.NET 0

ODataQueryOptions do not correctly apply $filter and $orderby Options to IQueryable when using EntityFramework 6 with SQL Server

This blog post is a bit more lengthly than my usual posts and the idea came from an issue I faced when working in one of our project where we use an OData v3 REST interface that talks to an MS SQL Server (2012 R2) via EntityFramework v6.1.3. In short: we wanted to implement ‘entity framework row level security’ (in […]

Various Products 0

ODataController throws ‘No NavigationLink factory was found’ when returning a different type in IHttpActionResult

Recently I ran into a strange error when working on an ODataController. On several occasions (especially on CREATE or UPDATE operations) we do not want to return the actual underlying entity of the controller, but instead would like to return an entity that can be used for synchronisation such as a Job. So instead of doing something like this and […]

C#/.NET 0

Using CodeContracts with OData Controllers and Web.Api Exception Filters

When writing ODATA controllers for our projects we spend quite some time on writing boilerplate code and input parameter validation. In addition, for our error handling we would like detailed information for internal troubleshooting but not so detailed information sent back to the client (i.e. no stack traces). In order to achieve this without extra work we started looking at […]

LightSwitch 15

Consuming ODATA Services from LightSwitch with Impersonation

In case you are still using LightSwitch and are not entirely relying on its internal features, you might have started using ODATA services as LightSwitch data sources. This comes in especially handy when combined with the Microsoft Managed Extensibility Framework (MEF) which lets you create decoupled components that can be easily plugged into your core application. However, as soon your […]

C#/.NET 1

[HOWTO] Impersonate Calls to OData Service Reference

While working with OData controllers I came accross a challenge concerning authentication. The used authentication mode is Windows Authentication. I wanted to invoke an OData controller through a service reference from another OData controller with the user of the original call. The user of the original call has to be impersonated because the controller encapsulated as a service reference checks, […]

C#/.NET 0

Unit Testing OData Controllers with the Katana TestServer and Service References

Today I would like to quickly present you how to unit test Web.API based OData Controllers the easy way. On biz.dfch.CS.Examples.Odata you find a complete code example and some accompanying information. The idea is based on the following information (and slightly enhanced): * Unit Testing Web API OData Services – Part 1 * Unit Testing Web API OData Services – […]

PowerShell 0

[Bug] Class Library Service Reference for ODATA service does not handle return type from CRUD operations

Recently I observed a strange behavior when working with an ODATA service via a “System.Data.Services.Client.DataServiceContext” that was wrapped inside a class library (via a regular “Service Reference”). The specific ODATA service in question was an Entity Framework v4.1 based service and had defined two different entity sets (“Objects” and “Tasks”) along with its regular CRUD operations. The specialty of the […]