using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.OpenAccess;
using Telerik.OpenAccess.Query;

namespace _3_ReverseMap
{
  class Program
  {
    static void Main(string[] args)
    {
      using (IObjectScope scope = ObjectScopeProvider1.ObjectScope())
      {
        Query<Customer> query =
          scope.GetSqlQuery<Customer>("select * from Customers", "");
        
        QueryResultList<Customer> customers = query.ExecuteList();
        foreach (Customer customer in customers)
        {
          Console.WriteLine("Customer: {0}:", customer.CompanyName);
          foreach (Order order in customer.Orders)
          {
            Console.WriteLine("\tOrder: {0}:", order.OrderID);
            foreach (OrderDetail orderDetail in order.OrderDetails)
            {
              Console.WriteLine("\t\tProduct: {0}:",
                orderDetail.Product.ProductName);
            }
          }
        }
      }
      Console.ReadLine();
    }
  }
}
