Skip to content

Instantly share code, notes, and snippets.

@alieniasty
Created January 19, 2018 14:51
Show Gist options
  • Save alieniasty/05749a0c6d5bd45aec35b3df99b572c6 to your computer and use it in GitHub Desktop.
Save alieniasty/05749a0c6d5bd45aec35b3df99b572c6 to your computer and use it in GitHub Desktop.
/*
There are options to disable Lazy Loading in an Entity Framework.
After turning Lazy Loading off, you can still load the entities by explicitly calling the Load method for the related entities.
*/
User usr = dbContext.Users.FirstOrDefault(a => a.UserId == userId);
dbContext.Entry(usr).Reference(usr => usr.UserDetails).Load();
/*
There are two ways to use Load method:
.Reference - to load single navigation property
.Collection - to load collections.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment