Search code examples
linqentity-frameworklinq-to-entitieswcf-data-servicesodata

Filtering odata results based on a value contained in a navigation property


Using the Northwind OData feed available at http://services.odata.org/Northwind/Northwind.svc/, how would one go about getting back a list of Employees that are assigned to TerritoryID = 19713?

I can get the Employees and territories using the following LINQ query, but without the All/Any methods, I'm not sure how to do what I'm asking.

from e in Employees.Expand("Territories") select e

I'm assuming this is simple and I'm just not seeing the forest for the trees...so, thanks in advance for your help.


Solution

  • In this case, you can turn it around

    Territories.Expand("Employees").Where (t => t.TerritoryID == "19713")
    

    But generally, linq to odata has a very restricted subset of operands. Methods like Any or Contains, which would be useful in similar queries in e.g. linq to entities, are not supported.