How to: Navigate Relationships Using Navigation Properties

This topic shows how to navigate relationships through navigation properties (references). The example gets all the orders which ShipCity is "Lyon". The Order.Customer navigation property is used to get the Customer object.

To run the code in this example, you need to create a new Telerik Data Access Domain Model based on the Northwind database.

The following code is the LINQ example.

C#


    using ( EntitiesModel dbContext = new EntitiesModel() )
    {
       var query = from order in dbContext.Orders
                   where order.ShipCity == "Lyon"
                   select new
                   {
                       order.OrderID,
                       order.Customer
                   };
       foreach ( var item in query)
       {
           Console.WriteLine( "OrderId: {0}, CustomerId: {1}, CustomerCountry: {2}", item.OrderID, item.Customer.CustomerID, item.Customer.Country );
       }
    }

VB.NET


    Using dbContext As New EntitiesModel()
     Dim query = From order In dbContext.Orders
        Where order.ShipCity = "Lyon"
        Select New With {Key order.OrderID, Key order.Customer}
     For Each item In query
      Console.WriteLine("OrderId: {0}, CustomerId: {1}, CustomerCountry: {2}", item.OrderID, item.Customer.CustomerID, item.Customer.Country)
     Next item
    End Using

See Also