I commented out the line of code that enables lazy loading from all the ctor overloads for my ObjectContext class, yet when I iterate over a navigational property, the iteration is successful. Why?
Here's the relevant bits of code.
public MyExpensesEntities() :
base("name=MyExpensesEntities", "MyExpensesEntities")
{
// this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
static void Main(string[] args)
{
AddExpenses();
Console.WriteLine("Lazy loading is {0}.",
_context.ContextOptions.LazyLoadingEnabled ?
"enabled": "disabled");
PrintCategorywiseExpenses();
_context.Dispose();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
static void PrintCategorywiseExpenses()
{
foreach (var cateogry in _context.Categories)
{
Console.WriteLine
("Category: {0}\n----------------",
cateogry.CategoryName);
foreach (var e in cateogry.Expenses)
Console.WriteLine
("\tExpense: {0}\tAmount: {1}",
e.Particulars, e.Amount.ToString("C"));
}
Console.WriteLine();
}