Data Access has been discontinued. Please refer to this page for more information.

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 a fluent model based on the Northwind database.

The following code is the LINQ example.

using ( FluentModel dbContext = new FluentModel() )
{
   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 );
   }
}
Using dbContext As New FluentModel()
 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