Skip to content

Retrieving linked entries without fetching its owners

Jason Finch edited this page Aug 23, 2018 · 16 revisions

In addition to expanding results with associated data it's possible to navigate to linked entries directly, without fetching it's relationship principle. The relationship must be defined in OData service schema.


Find all products associated with a category with the given name

Untyped syntax

var products = await client
    .For("Categories")
    .Filter("CategoryName+eq+%27Beverages%27")
    .NavigateTo("Products")
    .FindEntriesAsync();
Assert.NotEmpty(products);

Typed syntax

var products = await client
    .For<Categories>()
    .Filter(x => x.CategoryName == "Beverages")
    .NavigateTo<Products>()
    .FindEntriesAsync();
Assert.NotEmpty(products);

Dynamic syntax

var x = ODataFilter.Expression;
var products = await client
    .For("Categories")
    .Filter(x.CategoryName == "Beverages")
    .NavigateTo(x.Products)
    .FindEntriesAsync();
Assert.NotEmpty(products);

Request URI: GET Products?$filter=Category%2fCategoryName+eq+%27Beverages%27


Find all employees for a superior with the given name

Untyped syntax

var x = ODataFilter.Expression;
var employees = await client
    .For("Employees")
    .Filter("Superior/FirstName+eq+%27Nancy%27 and Superior/LastName+eq+%27Davolio%27")
    .FindEntriesAsync();
Assert.NotEmpty(employees);

Typed syntax

var employees = await client
    .For<Employees>()
    .Filter(x => x.Superior.FirstName == "Andrew" && x.Superior.LastName == "Fuller")
    .FindEntriesAsync();
Assert.NotEmpty(employees);

Dynamic syntax

var x = ODataFilter.Expression;
var employees = await client
    .For(x.Employees)
    .Filter(x.Superior.FirstName == "Andrew" && x.Superior.LastName == "Fuller")
    .FindEntriesAsync();
Assert.NotEmpty(employees);

Request URI: GET Employees?$filter=Superior/FirstName+eq+%27Nancy%27 and Superior/LastName+eq+%27Davolio%27


Find all orders for an employee with the given name

Untyped syntax

var x = ODataFilter.Expression;
var orders = await client
    .For("Employees")
    .Filter("FirstName+eq+%27Andrew%27 and LastName+eq+%27Fuller%27")
    .NavigateTo("Orders")
    .FindEntriesAsync();
Assert.NotEmpty(orders);

Typed syntax

var orders = await client
    .For<Employees>()
    .Filter(x => x.FirstName == "Andrew" && x.LastName == "Fuller")
    .NavigateTo<Orders>()
    .FindEntriesAsync();
Assert.NotEmpty(orders);

Dynamic syntax

var x = ODataFilter.Expression;
var orders = await client
    .For(x.Employees)
    .Filter(x.FirstName == "Andrew" && x.LastName == "Fuller")
    .NavigateTo(x.Orders)
    .FindEntriesAsync();
Assert.NotEmpty(orders);

Request URI: GET Orders?$filter=Employee/FirstName+eq+%27Andrew%27 and Employee/LastName+eq+%27Fuller%27


Find all orders for a customer identified by key

Untyped syntax

var orders = await client
    .For("Customer")
    .Key("ALFKI")
    .NavigateTo("Orders")
    .FindEntriesAsync();
Assert.NotEmpty(orders);

Typed syntax

var orders = await client
    .For<Customers>()
    .Key("ALFKI")
    .NavigateTo<Orders>()
    .FindEntriesAsync();
Assert.NotEmpty(orders);

Dynamic syntax

var x = ODataFilter.Expression;
var orders = await client
    .For(x.Customers)
    .Key("ALFKI")
    .NavigateTo(x.Orders)
    .FindEntriesAsync();
Assert.NotEmpty(orders);

Request URI: GET Customers('ALFKI')/Orders


Find all order details for an order identified by key

Untyped syntax

var orderDetails = await client
    .For("Orders")
    .Key(10952)
    .NavigateTo("OrderDetails")
    .FindEntriesAsync();
Assert.NotEmpty(orderDetails);

Typed syntax

var orderDetails = await client
    .For<Orders>()
    .Key(10952)
    .NavigateTo<OrderDetails>()
    .FindEntriesAsync();
Assert.NotEmpty(orderDetails);

Dynamic syntax

var x = ODataFilter.Expression;
var orderDetails = await client
    .For(x.Orders)
    .Key(10952)
    .NavigateTo(x.OrderDetails)
    .FindEntriesAsync();
Assert.NotEmpty(orderDetails);

Request URI: GET Orders(10952)/OrderDetails


Find all employee's subordinates

Untyped syntax

var subordinates = await client
    .For("Employees")
    .Key(2)
    .NavigateTo("Subordinates")
    .FindEntriesAsync();
Assert.NotEmpty(subordinates);

Typed syntax

var subordinates = await client
    .For<Employees>()
    .Key(2)
    .NavigateTo(x => x.Subordinates)
    .FindEntriesAsync();
Assert.NotEmpty(subordinates);

Dynamic syntax

var x = ODataFilter.Expression;
var subordinates = await client
    .For(x.Employees)
    .Key(2)
    .NavigateTo(x.Subordinates)
    .FindEntriesAsync();
Assert.NotEmpty(subordinates);

Request URI: GET Employees(1)/Subordinates


Find a superior for an employee identified by key

Untyped syntax

var superior = await client
    .For("Employees")
    .Key(1)
    .NavigateTo("Superior")
    .FindEntryAsync();
Assert.NotNull(superior);

Typed syntax

var superior = await client
    .For<Employees>()
    .Key(1)
    .NavigateTo(x => x.Superior)
    .FindEntryAsync();
Assert.NotNull(superior);

Dynamic syntax

var x = ODataFilter.Expression;
var superior = await client
    .For(x.Employees)
    .Key(1)
    .NavigateTo(x.Superior)
    .FindEntryAsync();
Assert.NotNull(superior);

Request URI: GET Employees(1)/Superior


Find a superior for an employee identified by EmployeeID

Untyped syntax

var superior = await client
    .For("Employees")
    .Filter("EmployeeID+eq+1")
    .NavigateTo("Superior")
    .FindEntryAsync();
Assert.Equal(2, superior.EmployeeID);

Typed syntax

var superior = await client
    .For<Employees>()
    .Filter(x => x.EmployeeID == 1)
    .NavigateTo(x => x.Superior)
    .FindEntryAsync();
Assert.Equal(2, superior.EmployeeID);

Dynamic syntax

var x = ODataFilter.Expression;
var superior = await client
    .For(x.Employees)
    .Filter(x.EmployeeID == 1)
    .NavigateTo(x.Superior)
    .FindEntryAsync();
Assert.Equal(2, superior.EmployeeID);

Request URI: GET Employees(1)/Superior


See also:
Expanding results with linked entries
Retrieving data

Clone this wiki locally