tags:

views:

6

answers:

0

I am running the following code

    NorthwindDataContext db = new NorthwindDataContext("Data Source=(local);Integrated Security = true;Initial Catalog=Northwind");
    IQueryable<Customer> allCustomers = db.Customers.Take(2);

    db.Log = Console.Out;

    DataLoadOptions opt = new DataLoadOptions();
    opt.LoadWith<Customer>(cust => cust.Orders);
    db.LoadOptions = opt;

    Console.WriteLine("    ====>Starting to read the Customers");

    foreach (Customer cust in allCustomers)
    {
        Console.WriteLine("Customer Name is {0}", cust.ContactName);


        Console.WriteLine("    ====>Starting to read the Orders");
        foreach (Order ordr in cust.Orders)
            Console.WriteLine("Order Date is {0}",ordr.OrderDate );
        Console.WriteLine("    ====>Finished reading the Orders");
    }

    Console.WriteLine("    ====>Finished reading the Customers");

    Console.ReadKey();

In this case the immediate loading is not occuring.
If I remove the call to Take operator, then immediate loading indded happens.

Why is it so ?