Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Loading Related Data > Checking If a Navigation Property Has Been Loaded

Checking If a Navigation Property Has Been Loaded

The Reference and Collection methods also give you access to the IsLoaded property. The IsLoaded method will tell you whether the entire contents of the navigation property have been loaded from the database or not. The IsLoaded property will be set to true when lazy, eager, or explicit loading is used to load the contents of the navigation property. Add the TestIsLoaded method shown in Example 2-26.

Example 2-26. Testing if a navigation property has been loaded with IsLoaded

private static void TestIsLoaded()
{
  using (var context = new BreakAwayContext())
  {
    var canyon = (from d in context.Destinations
                  where d.Name == "Grand Canyon"
                  select d).Single();

    var entry = context.Entry(canyon);

    Console.WriteLine(
      "Before Load: {0}",
      entry.Collection(d => d.Lodgings).IsLoaded);

    entry.Collection(d => d.Lodgings).Load();

    Console.WriteLine(
      "After Load: {0}",
      entry.Collection(d => d.Lodgings).IsLoaded);
  }
}

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial